Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

On catalog page I need to show offer "expires in N days". It can be easily achieved if each product has defined Special Price and date individually for example $this->getProduct()->getSpecialToDate();, but if you set discount via Catalog Price Rule product has no information about discount currently applied and other related data.

I'm wandering how can I get information about current product discount rules used like date?

share|improve this question

1 Answer 1

I have not tried this, but I believe it's possible. I don't have the exact code, but I can provide you with it later when I have more free time if you really need it. This appraoch is pretty straightforward.

There's a table called catalogrule_product that stores Catalog Price Rules discounts per product and customer group. Note that this table needs to get indexed every time you make changes to your Catalog Price Rules. You can do this with the indexer or by clicking "Apply Rules" on this page (this could take long if you have a lot of products).

For a given product you have on a catalog (or any) page, get its entity_id and look it up on catalogrule_product.product_id. Make sure to check customer_group_id as well. Once you find the row(s) you're looking for, this row(s) will have have timestamps (in seconds) from_time and to_time for that given applied rule (rule_id).

Get its row_id and look this up on catalogrule if you need more information on the rule. The entry you find on catalogrule has from_date and to_date, and those are all you need to calculate what you want.

share|improve this answer
    
I think this approach is good, but be careful, I'm thinking about what happens if you have two rules on the same product? There is a column sort_order, however it is calculated, maybe it is useful? –  Fabian Blechschmidt Mar 12 at 14:15
    
It's possible that more than one rule applies for a given product, but Magento may index only the rule that applies for a given product. I haven't tested this. OP could probably run a few test scenarios? –  laketuna Mar 12 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.