0

I have made a little bit of code to show product that are on sale on the cart page but it is not displaying the sale price only the original.

This is the code that im using to show the price.

<?php echo Mage::helper('core')->formatPrice($_product->getPrice());?>

So the question is how can i change it so it shows the sale price if there is one?

Thank you

///////////ADDED////////

<?php 
$special_price = Mage::helper('core')->formatPrice($_product->getSpecialPrice());
$norm_price = Mage::helper('core')->formatPrice($_product->getPrice());?>
<?php if ($special_price){
 echo $special_price; 
} else { 
 echo $norm_price;
} ?>

Thanks again

2

Instead of using $_product->getPrice() use $_product->getFinalPrice() which returns the price including any reductions etc.

If you want the special price as entered in the backend special price field use $_product->getSpecialPrice()

To see if the product has a special price use the following code.

$specialPrice = $_product->getFinalPrice();
$normalPrice = $_product->getPrice();
if ($normalPrice != $specialPrice)
{
   // has special price
}
[...]
| improve this answer | |
  • Thank you that's exactly what i needed, knew it would eb something simple! thanks again! – Adam Allen Oct 14 '14 at 8:48
  • Hey, I added this if statement to check if the product has a special price and if true show the special price. That works perfectly but if the product doesn't have one it is not showing the normal price. Could you have a look i have added it to my question – Adam Allen Oct 14 '14 at 9:12
  • Updated my answer – Sander Mangel Oct 14 '14 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.