cancel
Showing results for 
Search instead for 
Did you mean: 

How to get which catalog price rule applied on particulate product list or product view page?

Highlighted
Contributor

How to get which catalog price rule applied on particulate product list or product view page?

We need to displayed Discount % as per applied catalog rule on that product in product view page or product listing page in Magento 1.9 version 

7 REPLIES
Contributor

Re: How to get which catalog price rule applied on particulate product list or product view page?

To make it a bit simpler, you could compare $_product->getPrice() against $_product->getFinalPrice();

 

<?php  $_price = $_product->getPrice();
       $finalPrice = $_product->getFinalPrice();
?>

    <?php if($_finalPrice < $_price): ?>
    <?php $_savingPercent = 100 - round(($_finalPrice / $_price)*100); ?>
        <p class="special-price savings">
            <span class="label"><?php echo $this->__('You Save!') ?></span>
            <span class="price">
                <?php echo $_savingPercent; ?>%
            </span>
        </p>
    <?php endif; ?>
Contributor

Re: How to get which catalog price rule applied on particulate product list or product view page?

Thanks for your reply @elflingWe did this in product view page. Again thanks @elfling

Contributor

Re: How to get which catalog price rule applied on particulate product list or product view page?

Hi, so problem resolved?

 

You could apply the same logic to list.phtml, replacing $_product with say $item or $_item depending on what your theme uses.

Contributor

Re: How to get which catalog price rule applied on particulate product list or product view page?

@elfling This is the code and we can use this in both product listing page and product view page.

$productId = $_product->getId();

$product = Mage::getModel('catalog/product')->load($productId);

$storeId = $product->getStoreId();
$websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
$dateTs = Mage::app()->getLocale()->storeTimeStamp($storeId);

if(Mage::getSingleton('customer/session')->isLoggedIn())
{
$customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
}
else
{
$customerGroupId = 0;
}

$resource = Mage::getResourceModel('catalogrule/rule');
$rules = $resource->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $productId);
foreach ($rules as $key => $value) {
echo "You Save ".round($value['action_amount'])."% Discount";
}

Contributor

Re: How to get which catalog price rule applied on particulate product list or product view page?

Interesting, however final price should have been enough, since final price calculates based on rules and customer groups.

Contributor

Re: How to get which catalog price rule applied on particulate product list or product view page?

 


elfling wrote:

Interesting, however final price should have been enough, since final price calculates based on rules and customer groups.


We used above code of rules only for Displayed Indication of the rule and discount %.

Contributor

Re: How to get which catalog price rule applied on particulate product list or product view page?

We used above code of rules only for Displayed Indication of the rule and discount %.