I want to check if there is a sales promotion on the product, and then stick the advertising label on this product on the category list page. But I donโt know how to go through all the rules of the shopping cart and get the products / categories associated with each rule.
EDITED
Thanks seanbreeden, but I can not pull skus from $conditions . var_dump($conditions); shows it:
{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}a:7:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:7:{s:4:"type";s:42:"salesrule/rule_condition_product_subselect";s:9:"attribute";s:3:"qty";s:8:"operator";s:2:">=";s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:{s:4:"type";s:32:"salesrule/rule_condition_product";s:9:"attribute";s:12:"category_ids";s:8:"operator";s:2:"==";s:5:"value";s:2:"23";s:18:"is_value_processed";b:0;}}}}}a:7:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:2:{i:0;a:5:{s:4:"type";s:32:"salesrule/rule_condition_address";s:9:"attribute";s:13:"base_subtotal";s:8:"operator";s:2:">=";s:5:"value";s:2:"45";s:18:"is_value_processed";b:0;}i:1;a:7:{s:4:"type";s:42:"salesrule/rule_condition_product_subselect";s:9:"attribute";s:3:"qty";s:8:"operator";s:2:">=";s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:{s:4:"type";s:32:"salesrule/rule_condition_product";s:9:"attribute";s:3:"sku";s:8:"operator";s:2:"==";s:5:"value";s:46:"test-config, BLFA0968C-BK001, BLFA0968C-CR033X";s:18:"is_value_processed";b:0;}}}}}a:6:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}a:6:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}a:7:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:7:{s:4:"type";s:42:"salesrule/rule_condition_product_subselect";s:9:"attribute";s:3:"qty";s:8:"operator";s:2:">=";s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:{s:4:"type";s:32:"salesrule/rule_condition_product";s:9:"attribute";s:3:"sku";s:8:"operator";s:2:"==";s:5:"value";s:16:"BLFA0968C-CR033X";s:18:"is_value_processed";b:0;}}}}}
but when I cross $ conditions, i.e.
$rules = Mage::getResourceModel('salesrule/rule_collection')->load(); foreach ($rules as $rule) { $conditions = $rule->getConditionsSerialized(); foreach ($conditions as $condition) { var_dump($condition); } }
he doesnโt show anything, so I donโt know how to pull here.
EDIT2 As Alaxander suggested, I do not use a non-esterialized approach. Now I do it like this:
$rules = Mage::getResourceModel('salesrule/rule_collection')->load(); foreach ($rules as $rule) { if ($rule->getIsActive()) { //print_r($rule->getData()); $rule = Mage::getModel('salesrule/rule')->load($rule->getId()); $conditions = $rule->getConditions(); $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++) { $skus[] = trim($string[$i]); } endforeach; endforeach; } } return $skus;
And then, checking the list page, if sku matches the $ skus array, then display the label. But again, there is a limitation with this approach. I am thinking of a different approach (I'm not sure if this is possible). Thinking of creating a new table (to save products sales rules). Always save the sales rule, catch the save rule event and update the table with the rule name and all related products. Then, on the list page, check that the table, if products exist in the table, shows the corresponding label. Now I think the event is adminhtml_controller_salesrule_prepare_save (not 100% sure), but I donโt know how to get sku from the rule condition in the observer to save in a new table.