Display Percentage or Amount of discount for catalog price rule in Magento

Display Percentage or Amount of discount for catalog price rule in Magento

August 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Display Percentage or Amount of discount for catalog price rule in Magento

Displaying Catalog Price Rule Discounts in Magento

Hello, developers! Today we’re going to tackle an interesting challenge: displaying the percentage or amount of discount applied by a catalog price rule in Magento.

Current Challenges Faced

Let’s address Remy’s concerns point by point:

  1. Loading CatalogRule model with product ID: You’re right that loading rules with a product ID isn’t straightforward. The CatalogRule model uses entity IDs for loading, which can be frustrating when working with products.

  2. Limited methods in price.phtml: The out-of-the-box price.phtml file indeed has limited functionality around catalog rules. It’s primarily focused on displaying the old and special prices.

  3. Difference between percentage and fixed amount rules: Catalog rules can be either percentage-based or a fixed amount. Knowing which type is applied to a product is crucial for accurate discount calculation.

Our Approach: Extending the Existing Price Helper

To solve this, we’ll extend Magento’s core price helper functionality. This allows us to keep modifications separate from the core and makes updates easier in the future.

First, create an observer that triggers before the sales block is rendered:

// app/code/Vendor/Module/etc/events.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/events.xsd">
    <event name="sales_block_abstrac_get_prices">
        <observer name="vendor_module_discount_provider" instance="Vendor\Module\Observer\DiscountProvider"/>
    </event>
</config>

Next, create the observer class:

// app/code/Vendor/Module/Observer/DiscountProvider.php
public function execute(\Magento\Framework\Event\Observer $observer)
{
    $block = $observer->getBlock();
    $productId = $block->getProduct()->getId();

    // Load catalog rules for the product
    $ruleCollection = $this->catalogRuleFactory->create()
        ->setProductFilter($productId)
        ->addFieldToSelect(['rule_id', 'simple_action'])
        ->load();

    foreach ($ruleCollection as $rule) {
        if ($rule->getSimpleAction() == 'fixed') {
            // Handle fixed amount rules
        } elseif ($rule->getSimpleAction() == 'percent') {
            // Handle percentage rules
        }
    }

    $block->setDiscountRules($rules);
}

Finally, modify the price.phtml file to use the new data:

// app/design/frontend/Vendor/theme/Magento_Theme/templates/catalog/product/price.phtml
<?php if ($block->getDiscountRules()): ?>
    <span class="discount-info">
        <?php foreach ($block->getDiscountRules() as $rule): ?>
            <?= $rule['type'] ?>: <?= $rule['value'] ?><br />
        <?php endforeach; ?>
    </span>
<?php endif; ?>

Conclusion

Displaying catalog price rule discounts in Magento isn’t an easy task out-of-the-box. However, with a bit of customization using observers and extending the core price helper functionality, we can achieve what we need.

Remember to clear your cache after making these changes!

If you’re interested in learning more about Magento development or looking for professional services, be sure to check out Laravel Company. They offer a range of services including Magento development and e-commerce solutions.

Thanks for reading! Let me know if you have any other questions.

Catalog API Extensions Themes

Our network