I’ve been looking at the salesrule_coupon table, and I’ve discovered that I can map many coupon codes to a single rule, if the rule itself is of type ‘Auto.’ This is highly convenient as my client needs us to sync the codes periodically with a feed of data.
So in loading in these thousands of codes (using a custom module & direct SQL calls) they load just fine, and I can test and verify that many of them work.
However in working my way down the list of these codes, they stop working. The first 30 or so will work just fine, but thereafter, Magento says that the codes are invalid.
I’m still debugging this, and I’ll post updates if I discover anything… but I’ve tried and experienced this with two separate price rules now. One rule crapped out at the 31st code, the second at the 39th.
What’s really strange is that, if I change these codes to point to a different rule (one with less than 30 codes) they’re recognized and accepted. Nothing else changed, that I can determine.
Any ideas on how to proceed here? Has anyone attempted this before? This is an interesting one.
I fixed the same issue when I was creating something similar for one of my customers. The source of the problem for retrieving of valid coupon Magento Core Sales Rule module uses
FIND_IN_SET()withGROUP_CONCAT()MySQL functions instead adding additional condition for joined table. SoFIND_IN_SETjust truncates number of coupon codes that are used in group concatenation to 31 item (32 bits mask). Also I noticed that they are using HAVING instead of where, so it affects performance a bit.So what you need to do are the following:
Mage_SalesRule_Model_Mysql4_Rule_Collection(salesrule/rule_collection)Then in your resource model that rewrites core one, you need to redefine this method
setValidationFilter($websiteId, $customerGroupId, $couponCode='', $now=null)that applies limitations for sales rules on the frontend. Here the method body that I used:Test fix & Enjoy Magento Development 🙂