6

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.

  • 1
    "I have made a custom function to display discount code and amount on details page." I would say you made a mistake here. Can you post your function? Please edit your post for this – Fabian Blechschmidt Mar 4 '13 at 13:46
  • I'm not sure what you mean by "how to get rule id of a shopping cart rule for Brand and SKU". Did you mean that you needed a list of all of the Shopping Cart Rules that contain a certain Brand or SKU? – seanbreeden Mar 14 '13 at 2:40
  • Yes that what i mean, if current product contain some brand or sku which assign for creating shopping cart rule – Mufaddal Mar 14 '13 at 4:12
4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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