VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product pricing => Topic started by: padalec on August 03, 2014, 20:31:16 PM

Title: Discounted prices in category view
Post by: padalec on August 03, 2014, 20:31:16 PM
Hi,

I needed to display prices like this:

- IF THERE IS A DISCOUNT strike REGULAR PRICE (add span="price-crosed")
- IF THERE IS NO DISCOUNT HIDE PRICE (add span="price-ok" and set display:none in css)

I managed to do this with the code below for products view. Now I want to do the same for category view (in category/deafult.php) .. , but the same code doesn't work:

Here is the code:


if (round($this->product->prices['basePriceWithTax'],$this->currency->_priceConfig['salesPrice'][1]) != round($this->product->prices['salesPrice'],$this->currency->_priceConfig['salesPrice'][1])) {
                     
   echo '<span class="price-crossed" >' . $this->currency->createPriceDiv ('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices) . "</span>";

}

if (round($this->product->prices['basePriceWithTax'],$this->currency->_priceConfig['salesPrice'][1]) == round($this->product->prices['salesPrice'],$this->currency->_priceConfig['salesPrice'][1])) {
                     
   echo '<span class="price-ok" >' . $this->currency->createPriceDiv ('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices) . "</span>";


Why it doesn't work?
Title: Re: Discounted prices in category view
Post by: padalec on August 03, 2014, 21:21:08 PM
Well, just after 20 minut I found a solution with my "coding logic". Can please someone explain me what I did  ;D

Here is the modified code in category/default.php:



if (round($product->prices['basePriceWithTax'],$this->currency->_priceConfig['salesPrice'][1]) != round($product->prices['salesPrice'],$this->currency->_priceConfig['salesPrice'][1])) {
                     
echo '<span class="price-crossed" >' . $this->currency->createPriceDiv ('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $product->prices) . "</span>";

}

if (round($product->prices['basePriceWithTax'],$this->currency->_priceConfig['salesPrice'][1]) == round($product->prices['salesPrice'],$this->currency->_priceConfig['salesPrice'][1])) {
                     
echo '<span class="price-ok" >' . $this->currency->createPriceDiv ('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $product->prices) . "</span>";

}


I just replaced $this->product->prices (see previous post) with $product->prices

Can someone with php knowledge tell me if this solutions is OK.

In front the result is ok for me ... but don't know if the logic behind is ok  :o

Thank you.
Title: Re: Discounted prices in category view
Post by: seyi on August 04, 2014, 13:10:01 PM
Yes, it is fine.  In the category view, there is more than one product, called through a foreach.  The handle for each product is $product.