I have configured the shopping cart price rule in Magento. Is it possible to fetch category IDs, product Ids that I configure in shopping cart price rule on product catalog page ?
If the product is eligible for some shopping cart price rule, I would like to get the shopping cart price rule name in product page ?
Awaiting for your valuable reply.
Best Answer
Very possible to do, and is really not limited to the type of Shopping Cart Rule Conditions.
The basic idea is to create a copy of the current quote object, inject your currently viewed product into 'said copy of quote', and then validate that copied quote object against your rule(s)
This way (most) rule conditions would be able to be used, and still get back a valid response.
Please note the following: I use this exact same idea to display a Gifting Icon, in my Gifting Promotions Extension, if a currently viewed item validates for gifting (if added to cart).
The code example below is thus using my gifting modules promo rule models, but you should be able to simply change that to the core Shopping Cart Rule models. The way my Gifting extension functionality works, is heavily based on the core way of doing the rules, so should be interchangeable. Even if not, the idea is here now :)
The code exists as a helper function, as I use it from product view and category list pages - I have added some comments in the code, but please ask if you need any clarifications.
Note that if you have a LOT of rules, this CAN, and WILL slow down your page load / display, unless cached. The routine below shows a way to use cache to help improve performance. Since the cache keys are known, you can easily add some hooks to product save, and rule saving to clear out the relevant cache blocks, so display is correct. of course a FPC will solve this as well)
So, now you have the idea, and enough babbling from me - show me the code!
The routine is simply called as such:
and itself is:
Good luck :)