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

前端 未结 4 512

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:23

    I would suggest you to do it like this. When you had a product to cart, each rules are checked to calculate the final price and reduction. You can know which rules are applied to each item of your cart. In the table sales_flat_quote_item you have the column applied_rule_ids. I think you can access to this in php, by a function getAllItemsInCart or something like this (you have to find out). After you do $item->getAppliedRuleIds() and finally you can get the name of the rule apply to an item (product).

    Good luck :)

    Edit:

    I read again your request and I think my answer doesn't fit with your request. Your case is even more complicated. For each product on your catalog page you have to apply all the rules of your website. But Mage_SalesRule_Model_Validator process expect item and not product... If you have lot of rules this task will slow down your catalog and this is really not good! The best would be to cache this result of the rules label in the database, may be in the table catalog_category_product or... (and even better to generate this cache automatically).

    Edit2:

    Other possibility would be to have a new field in rule creation where you set manually the related products (sku). You save this data in the table salesrule or in a new table salesrule_related_sku. Then when you display the catalog you check for the sku and if the rule still active. This solution would be the easiest one :-)

提交回复
热议问题