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?

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 7

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; ?>

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

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.

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";
}

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.

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 %.

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 %.