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
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; ?>
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.
@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";
}
Interesting, however final price should have been enough, since final price calculates based on rules and customer groups.
@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 %.
We used above code of rules only for Displayed Indication of the rule and discount %.