Showing the Original Price in Magento Cart Template
Introduction
In Magento, if you apply catalog price rules, the original price of the product might not be displayed clearly in the cart template by default. This can lead to confusion for customers who are unsure about the discount applied to their items. In this post, we will guide you through modifying the default.phtml file in your cart template to accurately display both the current and original prices side-by-side.
Understanding the Problem
The issue lies within the template > checkout > cart > item > default.phtml file where the product price is rendered. By default, Magento only displays the discounted price computed after applying tax rules. The crossed-out original price that appears in the catalog or product view page doesn’t automatically transfer to the cart.
Current Code Analysis
Let’s examine the relevant section of the default.phtml file:
<?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
<?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>
<?php else: ?>
<?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()) ?>
<?php endif; ?>
This code checks for applied tax and displays the total price with taxes included.
The Solution
To show both prices, we need to retrieve the original price before any discounts or tax calculations. We can use the getOriginalPrice() method available in Magento’s core product model (Mage_Catalog_Model_Product).
Here is how you can modify your default.phtml:
<?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
<span class="price"><?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?></span>
<del class="old-price">
<?php echo $this->helper('checkout')->formatPrice($_item->getOriginalPrice()); ?>
</del>
<?php else: ?>
<span class="price"><?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()) ?></span>
<del class="old-price">
<?php echo $this->helper('checkout')->formatPrice($_item->getOriginalPrice()); ?>
</del>
<?php endif; ?>
In this modified version, we have:
- Added the original price inside a
<del>tag for visual styling. - Used
getOriginalPrice()to retrieve the original pre-discounted price of the product.
Note: Make sure your theme directory is enabled and the changes are applied there. Also, ensure that you have properly configured tax rules and catalog price rules in your Magento admin panel.
Conclusion
Displaying the original price alongside the discounted price in the cart template provides better transparency for customers about their savings. By modifying the default.phtml file as shown above, you can achieve this without needing to override any core files or use third-party extensions. Remember that proper tax and discount calculations must be configured correctly for accurate pricing.
For more advanced customizations and debugging help with Magento templates, feel free to explore our other blog posts at Laravel Company.