Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cart Price rules without coupons are not processed when coupon is applied #2931

Closed
hatimeria-artur-jewula opened this issue Jan 8, 2016 · 15 comments
Labels
bug report Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@hatimeria-artur-jewula
Copy link
Contributor

I have stumbled on strange situation in Magento2. I have 2 cart price rules defined. First one has no conditions, no coupon, applied to all customer groups and websites, and grants 10% discount. This rule is successfully applied to cart after first item is added. I can see discount value set to 10%.

Example:
cart-rule-1

Now I have a second rule that uses specific coupon provided in rule and fixed discount of $5. When I enter the code into "Apply Discount Code" field I notice that it is being applied but the first one is not. Only coupon rule is being applied

cart-rule-2

Both rules have "Discard subsequent rules" set to no and no-coupon rule's priority is 0 whereas coupon rule's priority is 5. I would assume that both should be applied.

I dig into Magento\SalesRule\Model\ResourceModel\Rule\Collection class and found out that it produces the following query that fetches rules to check in method setValidationFilter()

SELECT `main_table`.*, `rule_coupons`.`code` FROM `salesrule` AS `main_table`
  INNER JOIN `salesrule_website` AS `website` ON website.website_id = '1' AND main_table.rule_id = website.rule_id
  INNER JOIN `salesrule_customer_group` AS `customer_group_ids` ON main_table.rule_id = customer_group_ids.rule_id AND customer_group_ids.customer_group_id = 0
  LEFT JOIN `salesrule_coupon` AS `rule_coupons` ON main_table.rule_id = rule_coupons.rule_id AND main_table.coupon_type != 1
WHERE (from_date is null or from_date <= '2016-01-08')
      AND (to_date is null or to_date >= '2016-01-08')
      AND (`is_active` = '1')
      AND (
        (
          main_table.coupon_type = 1
          OR (main_table.coupon_type = 3 AND rule_coupons.type = 0)
          OR (main_table.coupon_type = 2 AND main_table.use_auto_generation = 1 AND rule_coupons.type = 1)
          OR (main_table.coupon_type = 2 AND main_table.use_auto_generation = 0 AND rule_coupons.type = 0)
        )
        AND rule_coupons.code = 'ABC'
        AND (rule_coupons.expiration_date IS NULL OR rule_coupons.expiration_date >= '2016-01-08')
      )
      AND (`is_active` = '1') ORDER BY sort_order ASC;

The problematic line is AND rule_coupons.code = 'ABC' which removes all rules without coupons. I belive this should be set as AND (rule_coupons.code = 'ABC' OR (main_table.coupon_type = 1))

@mswaidan
Copy link

I'm having this issue as well. @hatimeria-artur-jewula did the change to AND (rule_coupons.code = 'ABC' OR (main_table.coupon_type = 1)) fix the issue for you?

@hatimeria-artur-jewula
Copy link
Contributor Author

My solution was in separate module in di.xml create preference for Rule\Collection

<preference for="Magento\SalesRule\Model\ResourceModel\Rule\Collection" type="Module\SalesRule\Model\Resource\Rule\Collection" />

In the collection class I override setValidationFilter method in a way that I add line

$noCouponCondition = $connection->quoteInto(
                'main_table.coupon_type = ? ',
                \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON
            );

just before $orWhereConditions and change line

$select->where('(' . $orWhereCondition . ') AND ' . $andWhereCondition);

to

$select->where($noCouponCondition . 'OR (' . $orWhereCondition . ') AND ' . $andWhereCondition);

@Mulderua
Copy link
Contributor

Hi @hatimeria-artur-jewula, thank you for issue report! Internal ticket MAGETWO-54440 was created.

@NadiyaS NadiyaS added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jun 15, 2016
@vkorotun vkorotun removed the CS label Aug 4, 2016
@heldchen
Copy link
Contributor

this seems still present in 2.1.1

@davepyro
Copy link

Hi @hatimeria-artur-jewula
Would it be possible to give more info on your module as I am having a similar issue and need a fix for it?
thanks
Dave

@heldchen
Copy link
Contributor

@davepyro
Copy link

Great thanks

@plauge
Copy link

plauge commented Nov 18, 2016

@heldchen - Sorry, Im new to Mag2. How can I use your patch. I can see it's a .diff file.
Thanks!

@heldchen
Copy link
Contributor

you apply the diff file with a patch tool to your codebase...

@NadiyaS NadiyaS removed their assignment Nov 18, 2016
@brizido
Copy link

brizido commented Dec 7, 2016

This is a very important fix - when is this getting incorporated in one of the future releases?

@josefbehr
Copy link
Contributor

My solution was in separate module in di.xml create preference for Rule\Collection

Beware of the parent::_initSelect() line though. If you extend the original class to only overwrite that one method, it will throw an exception, if you keep it as is. Must be changed to be AbstractCollection::_initSelect(). And I second the question for an official fix. Is anyone even still assigned to the issue?

@bh-ref
Copy link
Contributor

bh-ref commented Dec 22, 2016

seems to be fixed in CE 2.1.3, see also #6294 & d667480

@yosefkurniawan
Copy link

yosefkurniawan commented Feb 22, 2017

Hi, seems cart price rules is still not working properly yet in Magento 2.1.3.
The amount of multiple discount seems correct already, in my case I use 2 cart price rule, one is without coupon, the other is with coupon. But in the totals block in the sidebar of shopping cart page, all discount (with and without coupon) are merged being one line. I expect they should be written one line per discount.
and also if I apply two discount (both without coupon), let say the first one is discount 10% and the second one is discount 50%, the system will only apply one of them. In my case the second one is applied. Does anyone hav the same experience with this in Magento 2.1.3?

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Oct 12, 2017
@magento-engcom-team
Copy link
Contributor

@hatimeria-artur-jewula, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.3.0-dev, 2.2.0, 2.1.9

@magento-engcom-team magento-engcom-team added the Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch label Oct 12, 2017
@hatimeria-artur-jewula
Copy link
Contributor Author

Yes, this was fixed some time ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests