Question

I have made two simple shopping cart rules from backend.

The first has action which is based 'SKU is one of'.

The second has action based on 'Brand contains'.

I have made a custom function to display discount code and amount on details page.

But on listing page for Rule 1, I am seeing the Promo Code and Discount Amount of Rule 2.

Alternatively, pls suggest me how to get rule id of a shopping cart rule for Brand and SKU.

Was it helpful?

Solution

This is taken from a StackOverflow question that I participated in, but modified for your question.

This iterates through all of the Shopping Cart rules in the rule_collection, compares the product sku on the view page and echos the Coupon Code. Based on this code you can modify it to also get the coupon code for Brand.

$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
                    }
                }
            endforeach;
        endforeach;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top