Display collection of Shopping cart rules and products categories associated to each rule

前端 未结 4 587

I want to check if there is a sales promotion on the product then stick the promotion label on that product on category list page. But I don\'t know how to loop through all

4条回答
  •  粉色の甜心
    2021-01-06 10:47

    You could pull the getMatchingProductsIds from /app/code/core/Mage/CatalogRule/Model/Rule.php and compare them with the skus displayed on the category list page.

     $catalog_rule = Mage::getModel('catalogrule/rule')->load(1);  // ID of your catalog rule here, or you could leave off ->load(1) and iterate through  ->getCollection() instead
     $catalog_rule_skus = $catalog_rule->getMatchingProductIds();
    

    hth

    EDIT

    Here's a way to get the serialized conditions:

    $rules = Mage::getResourceModel('salesrule/rule_collection')->load();
    
    foreach ($rules as $rule) {
        $conditions = $rule->getConditionsSerialized();
        var_dump($conditions);
    }
    

    EDIT 2

    There would have to be a better way to do this. The only way I could pull that data was to unserialize then iterate with foreach through each layer. Anyone have any better ideas for this? This works but is very sloppy.

    $rules = Mage::getResourceModel('salesrule/rule_collection')->load();
    
    foreach ($rules as $rule) {
    
      if ($rule->getIsActive()) { 
    $conditions = $rule->getConditionsSerialized();
    $unserialized_conditions = unserialize($conditions);
    
    $unserialized_conditions_compact = array();
    
    foreach($unserialized_conditions as $key => $value) {
       $unserialized_conditions_compact[] = compact('key', 'value');
    }
    
    for ($i=0;$i $value) {
                            foreach($value as $key1 => $value1) {
                                    foreach($value1 as $key2 => $value2) {
                                            foreach($value2 as $key3 => $value3) {
                                                    $skus[] = explode(",",$value3['value']);
                                            }
                                    }
                            }
                    }
            }
    }
     }
    
    }
    
    var_dump($skus);
    

提交回复
热议问题