Display discount percentage in Magento Category View

Display discount percentage in Magento Category View

August 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Display discount percentage in Magento Category View

Displaying Discount Percentage in Magento Category View

As an experienced Magento developer, I often receive queries about customizing the category view without resorting to third-party extensions. In this post, we’ll explore how to display discount percentages for each product within a category listing.

Understanding Magento’s Core Functionality

Magento is built around the concept of price rules and catalog products. Each product can have multiple special prices associated with it through promotional rules. To access these prices in your template files, you need to leverage Magento’s object manager and price helper classes.

Step 1: Retrieving the Special Price

In your category listing block (usually located under app/code/core/Mage/Catalog/Block/Product/List.php), you can use Magento’s \Magento\Catalog\Helper\Product class to retrieve the special price for each product. Here’s an example of how to get the current tiered price:

$priceHelper = Mage::helper('catalog/product');
$product->getTierPrice($this->getCurrentCustomerGroupId(), 1);

This code fetches the appropriate tiered price based on the customer group and quantity specified.

Step 2: Calculating the Discount Percentage

To calculate the discount percentage, you need to compare the special price with the original product price. You can achieve this using basic arithmetic operations in your template file:

<?php $specialPrice = $_product->getTierPrice(); ?>
<?php $originalPrice = $_product->getPrice(); ?>

<?php if ($specialPrice && $specialPrice < $originalPrice): ?>
    <?php $discountPercent = (($originalPrice - $specialPrice) / $originalPrice) * 100; ?>
    <span class="price-percent-reduction"><?= round($discountPercent, 2); ?>%</span>
<?php endif; ?>

In this example, we first check if a special price is set and if it’s lower than the regular price. If both conditions are met, we calculate the discount percentage by finding the difference between the original and special prices, dividing that number by the original price, and then multiplying the result by 100 to get the percentage.

Step 3: Displaying the Discount Percentage

Now that you have calculated the discount percentage, you can display it in your template file. You can choose to place this information next to the product name or price, depending on your layout requirements. Don’t forget to wrap the output within appropriate HTML elements for better styling.

<block type="catalog/product_list" name="category_products" as="products">
    <action method="setCategoryId"><category_id>2</category_id></action>
    <!-- Add this line -->
    <action method="addAttributeToSelect"><name>special_price</name></action>
</block>

In the above XML snippet, we add special_price to the list of product attributes to be selected. This ensures that the special price data is loaded along with other product information.

Conclusion

Displaying discount percentages in Magento category listings doesn’t require installing an extension; it simply involves understanding how to access and manipulate product prices using Magento’s core functionality.

By retrieving the appropriate tiered price, calculating the discount percentage within your template file, and ensuring that the necessary price data is selected for each product, you can achieve this customization without any additional coding in PHP files.

This approach not only saves time but also adheres to Magento’s best practices by keeping the logic separate from the presentation layer. As a result, your code remains maintainable and easy to update as needed.

For more advanced customizations and tips on optimizing your Magento performance, feel free to explore our other blog posts at Laravel Company.

Catalog Extensions Themes Customers

Our network