The 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.
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
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;
}
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0