News:

Looking for documentation? Take a look on our wiki

Main Menu

Discounted prices in category view

Started by padalec, August 03, 2014, 20:31:16 PM

Previous topic - Next topic

padalec

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?

padalec

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.

seyi

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.
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate