Magento Questions Answered By Magento Experts

 

Welcome Guest. Sign in or Signup

22 Answers

Issue with Cart Price Rules (Coupon code discard promotion without coupon code)

Asked by: 4578 views Questions

Hello,

I use Magento 1.6 and I am facing a problem, I would like to know if someone can reproduce and even know if it’s a config problem or a bug.

I have 2 Cart Promotion Rules :
1 Free Shipping for everyone (promo launch of the site for everyone)
1 Rule 5 € discount (coupon code “TOTO”)

When I activate my code TOTO, other rules not working anymore and I pay attention to set the rules “Do not process subsequent rules” to NO.

If I remove the coupon code in the promotion (and therefore valid for everyone) the 2 rules are activated.

Strange? Does anyone can reproduce on its Magento?

 

Best regards,

 

 

22 Answers



  1. Magentist on Aug 30, 2011 Reply

    Hi Gael,

    Did you try making sure BOTH rules are set to “No” for “Stop Further Rules Processing”? And once that’s verified make sure to refresh ALL Magento cache and re-index all data.

    Let me know if that fixes it for you ;) .

    While you’re at it why not take a look at our popular Magento Themes and best selling Magento Extensions? ;)

    0 Votes Thumb up 1 Votes Thumb down 1 Votes



  2. gael on Aug 30, 2011 Reply

    Hi,

    Yes I’m sure !!

    And find a solution and it’s really a Magento Bug. When a coupon code is used, the Query select only the rules with this coupon code disregarding all others rules even those without coupon code.

    I override Mage_SalesRule_Model_Resource_Rule_Collection to change the SQL Query.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  3. Levi Wilcox on Sep 12, 2011 Reply

    I have the same problem… thought I was going nuts.

    +1 Votes Thumb up 1 Votes Thumb down 0 Votes



  4. Levi Wilcox on Sep 12, 2011 Reply

    How did you end up fixing it?

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  5. gael on Sep 13, 2011 Reply

    I override Mage_SalesRule_Model_Resource_Rule_Collection to change the SQL Query.

    I change the function :

    public function setValidationFilter($websiteId, $customerGroupId, $couponCode = ”, $now = null)
    {
    if (is_null($now)) {
    $now = Mage::getModel(‘core/date’)->date(‘Y-m-d’);
    }
    /* We need to overwrite joinLeft if coupon is applied */
    $this->getSelect()->reset();
    parent::_initSelect();

    $this->addFieldToFilter(‘website_ids’, array(‘finset’ => (int)$websiteId))
    ->addFieldToFilter(‘customer_group_ids’, array(‘finset’ => (int)$customerGroupId))
    ->addFieldToFilter(‘is_active’, 1);

    if ($couponCode) {
    $this->getSelect()
    ->joinLeft(
    array(‘rule_coupons’ => $this->getTable(‘salesrule/coupon’)),
    ‘main_table.rule_id = rule_coupons.rule_id ‘,
    array(‘code’)
    );
    $this->getSelect()->where(
    ‘(main_table.coupon_type = ? ‘, Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON
    );
    $this->getSelect()->orWhere(‘rule_coupons.code = ?)’, $couponCode);
    } else {
    $this->addFieldToFilter(‘main_table.coupon_type’, Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
    }
    $this->getSelect()->where(‘from_date is null or from_date getSelect()->where(‘to_date is null or to_date >= ?’, $now);
    $this->getSelect()->order(‘sort_order’);
    return $this;
    }

    to :

    public function setValidationFilter($websiteId, $customerGroupId, $couponCode = ”, $now = null)
    {

    if (is_null($now)) {
    $now = Mage::getModel(‘core/date’)->date(‘Y-m-d’);
    }
    /* We need to overwrite joinLeft if coupon is applied */
    $this->getSelect()->reset();
    parent::_initSelect();

    $this->addFieldToFilter(‘website_ids’, array(‘finset’ => (int)$websiteId))
    ->addFieldToFilter(‘customer_group_ids’, array(‘finset’ => (int)$customerGroupId))
    ->addFieldToFilter(‘is_active’, 1);

    if ($couponCode) {
    //$this->getSelect()->where(‘main_table.coupon_type ?’, Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
    $this->getSelect()
    ->joinLeft(
    array(‘rule_coupons’ => $this->getTable(‘salesrule/coupon’)),
    ‘main_table.rule_id = rule_coupons.rule_id ‘,
    array(‘code’)
    );
    $this->getSelect()->where(‘rule_coupons.code = ? or coupon_type=1′, $couponCode);
    } else {
    $this->addFieldToFilter(‘main_table.coupon_type’, Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
    }
    $this->getSelect()->where(‘from_date is null or from_date getSelect()->where(‘to_date is null or to_date >= ?’, $now);
    $this->getSelect()->order(‘sort_order’);

    return $this;
    }

    +1 Votes Thumb up 1 Votes Thumb down 0 Votes



  6. gael on Sep 13, 2011 Reply

    I override Mage_SalesRule_Model_Resource_Rule_Collection to change the SQL Query.

    I found that Magento dos not care about others rules as soon as a Coupon Code is entered.

    So I rewrite the SQL Query to change that.
    My Query get all the rules without coupon code and the One with coupon code if submitted.

    I change the function :

    public function setValidationFilter($websiteId, $customerGroupId, $couponCode = ”, $now = null)
    {
    if (is_null($now)) {
    $now = Mage::getModel(‘core/date’)->date(‘Y-m-d’);
    }
    /* We need to overwrite joinLeft if coupon is applied */
    $this->getSelect()->reset();
    parent::_initSelect();
    $this->addFieldToFilter(‘website_ids’, array(‘finset’ => (int)$websiteId))
    ->addFieldToFilter(‘customer_group_ids’, array(‘finset’ => (int)$customerGroupId))
    ->addFieldToFilter(‘is_active’, 1);
    if ($couponCode) {
    $this->getSelect()
    ->joinLeft(
    array(‘rule_coupons’ => $this->getTable(‘salesrule/coupon’)),
    ‘main_table.rule_id = rule_coupons.rule_id ‘,
    array(‘code’)
    );
    $this->getSelect()->where(
    ‘(main_table.coupon_type = ? ‘, Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON
    );
    $this->getSelect()->orWhere(‘rule_coupons.code = ?)’, $couponCode);
    } else {
    $this->addFieldToFilter(‘main_table.coupon_type’, Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
    }
    $this->getSelect()->where(‘from_date is null or from_date getSelect()->where(‘to_date is null or to_date >= ?’, $now);
    $this->getSelect()->order(‘sort_order’);
    return $this;
    }

    to :
    public function setValidationFilter($websiteId, $customerGroupId, $couponCode = ”, $now = null)
    {
    if (is_null($now)) {
    $now = Mage::getModel(‘core/date’)->date(‘Y-m-d’);
    }
    /* We need to overwrite joinLeft if coupon is applied */
    $this->getSelect()->reset();
    parent::_initSelect();
    $this->addFieldToFilter(‘website_ids’, array(‘finset’ => (int)$websiteId))
    ->addFieldToFilter(‘customer_group_ids’, array(‘finset’ => (int)$customerGroupId))
    ->addFieldToFilter(‘is_active’, 1);
    if ($couponCode) {
    //$this->getSelect()->where(‘main_table.coupon_type ?’, Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
    $this->getSelect()
    ->joinLeft(
    array(‘rule_coupons’ => $this->getTable(‘salesrule/coupon’)),
    ‘main_table.rule_id = rule_coupons.rule_id ‘,
    array(‘code’)
    );
    $this->getSelect()->where(‘rule_coupons.code = ? or coupon_type=1′, $couponCode);
    } else {
    $this->addFieldToFilter(‘main_table.coupon_type’, Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
    }
    $this->getSelect()->where(‘from_date is null or from_date getSelect()->where(‘to_date is null or to_date >= ?’, $now);
    $this->getSelect()->order(‘sort_order’);
    return $this;
    }

    +2 Votes Thumb up 2 Votes Thumb down 0 Votes



  7. Levi Wilcox on Sep 13, 2011 Reply

    Thanks! Although I believe there is an error towards the end of your code.

    You have

    $this->getSelect()->where(‘from_date is null or from_date getSelect()->where(‘to_date is null or to_date >= ?’, $now);
    $this->getSelect()->order(‘sort_order’);
    return $this;
    }

    Works great after.

    It should be

    $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;
    
    }

    +1 Votes Thumb up 1 Votes Thumb down 0 Votes



  8. gael on Sep 13, 2011 Reply

    $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');

    Yes that’s my query , that was a bad Copy-Paste :-)

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  9. snh on May 04, 2012 Reply

    Hi, we have the following.

    1 coupon gives free shipping (priority 10), further rules YES: coupon code PICKUP 1 coupon gives 10$ discount (priority 20), further rules NO: coupon code 10OFF 1 coupon gives 5% discount (priority 50), further rules NO: no code, triggered by value

    If I enter 10OFF, followed by PICKUP the result is; 5% discount and free shipping (not the expected 10OFF and free shipping)

    I would expect the system to use the PICKUP coupon first with lowest prio 10, then continue processing us yes, so it moves to the 10OFF coupon code with prio 20, and then stop because further rules processing is NO

    But this is not working either. Magento 1.7.0.0.

    +1 Votes Thumb up 1 Votes Thumb down 0 Votes



    • gael on May 04, 2012 Reply

      0 is the upper priority

      0 Votes Thumb up 0 Votes Thumb down 0 Votes



      • snh on May 04, 2012

        I dont understand. So it does PRIO 10 first followed by PRIO 20?

        -1 Votes Thumb up 0 Votes Thumb down 1 Votes



  10. gael on May 04, 2012 Reply

    Yes exactly.

    the Free Shipping is the first rule to get activated.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  11. snh on May 07, 2012 Reply

    1 coupon code gives free shipping (priority 10), stop further rules = NO (PICKUP)

    1 coupon code gives 10$ off (priority 20), stop further rules = NO (DISCOUNT)

    Now when we enter PICKUP followed by DISCOUNT (or the other way around for that matter) all discounts are lost and not working.

    Magento 1.7.0.0.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  12. gael on May 07, 2012 Reply

    You can’t apply multi-coupon.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



    • snh on May 07, 2012 Reply

      Meaning? free shipping does not work with discount?

      2 discount codes 10$ off and 5% discount, both with coupon do work

      0 Votes Thumb up 0 Votes Thumb down 0 Votes



  13. gael on May 07, 2012 Reply

    I never saw 2 coupon applied in the same time, and for all I know it’s not possible we a base Magento.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  14. gael on May 07, 2012 Reply

    I just try on fresh install of Magento 1.7.

    If I try to put 2 coupon code, each one cancel the previous entered.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  15. snh on May 07, 2012 Reply

    Interesting? stop furter rules on first rule set to no?

    http://shirtsofholland.com/checkout/cart/

    add more than 3 products

    with code EK2012DRKIM 2 discounts are triggered 10 EURO off and a 5% discount triggered bu the more than 3 products

    see the comma between messages in the discount row

    EK KORTING 10 EURO, STAFFEL 5%

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  16. gael on May 07, 2012 Reply

    Ok, we don’t understand each over.

    you confuse coupon codes and promotion.

    You can apply 1 Coupon code and it trigger several promotion
    You cannot apply several coupon code in the same time.

    If you check the code I sent the 13 september 2011, it will solve your problem.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  17. snh on May 07, 2012 Reply

    Hi, lets PM. http://shirtsofholland.com/contactformulier

    We have 2 promotions/cart rule that use coupon codes

    1 for discount (in price)

    1 to unlock free shipping

    For this to work, do we need the above fix? (and do you have a copy of the final code after the bad copy/paste) Then we can try.

    In addition do both codes then follow a sequential prio path (both set to further rules = no); or does one cooupon code need prio 1 and the second prio 2 (sequential)

    many thanks

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  18. snh on May 14, 2012 Reply

    It looks like more was changed in Mage 1700

    the function to overrule has changed significantly

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  19. Magento Shopping Cart Rule Class Override Module | PHP Developer Resource on May 23, 2012 Reply

    [...] Question: I am attempting to write a module that corrects the behavior based on this post: Magento Issue with Cart Price [...]

    0 Votes Thumb up 0 Votes Thumb down 0 Votes


Answer Question