I want to display the coupon code on the product page. In shopping cart price rules, I have applied coupons to a particular category. I want to display the coupon on every product page whose category id is specified in shopping cart price rules.

$current_sku=$_product->getSku(); // Sku you are looking for

$rules = Mage::getResourceModel('salesrule/rule_collection')->load();

foreach ($rules as $rule) {
if ($rule->getIsActive()) {
    $rule = Mage::getModel('salesrule/rule')->load($rule->getId()); 

    $conditions = $rule->getConditions()->asArray();

    foreach( $conditions['conditions'] as $_conditions ):
        foreach( $_conditions['conditions'] as $_condition ):
            $string = explode(',', $_condition['value']);
            for ($i=0; $i<count($string); $i++) {
                $sku = trim($string[$i]);
                if ($sku==$current_sku) {
                        echo $rule->getCouponCode(); // Return coupon code that matches the sku condition

ref- Get Shopping cart rule coupon code

1 Answer 1


ou can get applied shopping cart price rules on product page with below function

public function getShoppingCartRules($product) {
    $now = Mage::getModel('core/date')->date('Y-m-d');
    $productData = new Varien_Object();
    $data = array(
        'product' => $product,
        'qty' => 1,
        'price' => $product->getFinalPrice(),
        'base_row_total' => $product->getFinalPrice()
    $allItems = new Varien_Object();
    $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();

    $ruleCollection = Mage::getResourceModel('salesrule/rule_collection')
            ->addFieldToFilter('discount_amount', array("gt" => '0'))
            ->addFieldToFilter('coupon_type', array(1,2,3))
            ->setOrder('sort_order', 'DESC')
            ->addWebsiteGroupDateFilter(Mage::app()->getStore()->getWebsiteId(), $customerGroupId);
            ->where('from_date is null or from_date <= ?', $now)
            ->where('to_date is null or to_date >= ?', $now);

    if ($ruleCollection->count()) {
            if ($rule->getActions()->validate($productData) && $rule->validate($allItems)) {
                $shoppingCartRules[] = $rule;
        return $shoppingCartRules;
    return null;

where $product is product object already exist on product page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.