Magento – Programmatically check is specific coupon is valid for product

couponcoupon-codesmagento-1.9

We have a Magento CE 1.9x shop that we developed a message that shows on the product page with a coupon, but we need to ONLY show the message IF the coupon (price rule) IS VALID for that item. Is there a reasonably simple way to test if the coupon is valid for that item WITHOUT actually applying it?

Best Answer

Since the conditions tie a coupon (salesrule) to a product you could check the conditions_serialized field in the salesrule table.

The conditions are serialized before storing it in there but with some fancy mapping I'm sure you can check if a certain SKU is in the conditions.

Still, I'm guessing you only have a limited amount of coupons. A simpler and cleaner solution would probably be to make an attribute where you indicate per product what coupon applies. But that might also depend on the number of products you have

Related Topic