Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5999469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:33:24+00:00 2026-05-23T00:33:24+00:00

I’ve been looking at the salesrule_coupon table, and I’ve discovered that I can map

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:33:25+00:00Added an answer on May 23, 2026 at 12:33 am

    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() with GROUP_CONCAT() MySQL functions instead adding additional condition for joined table. So FIND_IN_SET just 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:

    1. Create rewrite for this resource model: Mage_SalesRule_Model_Mysql4_Rule_Collection (salesrule/rule_collection)
    2. 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:

      /**
       * Fix for validation with auto-coupons
       * @todo remove this fix, after the bug in core will be fixed
       *
       * (non-PHPdoc)
       * @see Mage_SalesRule_Model_Mysql4_Rule_Collection::setValidationFilter()
       */
      public function setValidationFilter($websiteId, $customerGroupId, $couponCode='', $now=null)
      {
          if (is_null($now)) {
              $now = Mage::getModel('core/date')->date('Y-m-d');
          }
      
          $this->getSelect()->where('is_active=1');
          $this->getSelect()->where('find_in_set(?, website_ids)', (int)$websiteId);
          $this->getSelect()->where('find_in_set(?, customer_group_ids)', (int)$customerGroupId);
      
          if ($couponCode) {
              $couponCondition = $this->getConnection()->quoteInto(
                  'extra_coupon.code = ?',
                  $couponCode
              );
      
              $this->getSelect()->joinLeft(
                  array('extra_coupon' => $this->getTable('salesrule/coupon')),
                  'extra_coupon.rule_id = main_table.rule_id AND extra_coupon.is_primary IS NULL AND ' . $couponCondition,
                  array()
              );
              $this->getSelect()->where('('
                  . $this->getSelect()->getAdapter()->quoteInto(' main_table.coupon_type <> ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
                  . $this->getSelect()->getAdapter()->quoteInto(' OR primary_coupon.code = ?', $couponCode) . ')'
              );
              $this->getSelect()->where('('
                  . $this->getSelect()->getAdapter()->quoteInto(' main_table.coupon_type <> ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO)
                  . $this->getSelect()->getAdapter()->quoteInto(' OR extra_coupon.code IS NOT NULL') . ')'
              );
          } else {
              $this->getSelect()->where('main_table.coupon_type = ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
          }
          $this->getSelect()->where('from_date is null or from_date<=?', $now);
          $this->getSelect()->where('to_date is null or to_date>=?', $now);
          $this->getSelect()->order('sort_order');
      
          return $this;
      }
      
    3. Test fix & Enjoy Magento Development 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.