magento2: "Subtotal (Excl. Tax)" condition for Cart rule is not working for FREE Shipping

Preconditions and environment

  • Magento version 2.4.3-p2
  • Enable Tablerate shipping

Steps to reproduce

Backend

  1. Create a cart rule with following
  • {{{}Conditions{}}}: Subtotal (Excl. Tax) is equals or greater than 100
  • {{{}Actions{}}}: Free Shipping = For matching items only
  1. Create another cart rule with coupon XYZ to give a Fixed amount discount for whole cart of 10

Storefront

  1. Add items to the cart to make a subtotal of 105
  2. Apply the coupon XYZ to get 10$ OFF

Expected result

The shipping fee should not be 0 (i.e. FREE shipping cart rule should not be applied)

Actual result

The shipping fee is showing 0 (i.e. FREE shipping cart rule is applied)

Additional information

!https://user-images.githubusercontent.com/1205071/213676297-f3145d58-e179-47fb-aebc-19d5edb4e47a.png|width=593,height=348!

Quick n Dirty Solution

Step debugging showed that the value provided by the $address->getData('base*subtotal_with*discount') is not correct: !https://user-images.githubusercontent.com/1205071/213677260-afb0ac81-6fd1-450a-a945-3212f479f63c.png|width=509,height=152!

So ended up tweaking as below:

\Magento\OfflineShipping\Model\SalesRule\Calculator::processFreeShipping() ``{{ public function processFreeShipping(\Magento\Quote\Model\Quote\Item\AbstractItem $item) { $address = $item->getAddress();

$item->setFreeShipping(false);

foreach ($this->_getRules($address) as $rule) {

/* Quick Fix - Start / $address->setBaseSubtotalWithDiscount($address->getBaseSubtotal() + $address->getBaseDiscountAmount()); / Quick Fix - End */

/* @var $rule \Magento\SalesRule\Model\Rule */ if (!$this->validatorUtility->canProcessRule($rule, $address))

{ continue; }

}}``

Release note

No response

Triage and priority

  • < ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ > Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 24 (14 by maintainers)

Most upvoted comments

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket AC-7886 by the internal team Related commits: https://github.com/magento/magento2/search?q=AC-7886&type=commits

Based on the Jira ticket, the target version is 2.4.7-beta1.

Thanks

Hi @engcom-Bravo , @MagePsycho ,

In Adobe Magento, we can add multiple cart rules at a time without coupon code

So, Here the scenario is

Rule 1 :- Without COUPON a. Subtotal will be equal or greater than 100 . b. Free Shipping for item matching only.

Rule 2 :- With COUPON, Apply discount for the whole cart amount is 10%.

In Cart, we have product subtotal above 100,

Scenario 1:- let assume as 105

so Rule 1 will apply without coupon , so Table Rate shipping come to zero 
next Rule 2 with coupon can apply along with this Rule 1 , because  we made Discard Subsequent Rules = No in both cart rules.

Scenario 2:- let assume as 90

    Rule 1 will not apply without coupon , because  its not upto the condition, so we have table rate shipping value.
next Rule 2 with coupon can apply .

Scenario 1 is expected , Please let me know if i was understanding in different way. So, this is not a valid issue.

The issue I am raising is: “Subtotal (Excl. Tax)” condition doesn’t care about the discount, ideally it should.

So if you configure the FREE shipping cart rule with Subtotal (Excl. Tax) >= 100 (for example). And in the storefront, you apply a discount of 10 (for example, via coupon code or whatever) for a cart with a subtotal of 105 (for example). In this case, Subtotal (Excl. Tax) becomes 105 - 10 = 95, and FREE should not get applied.

But Magento is still giving FREE shipping (but it shouldn’t).

Note that Subtotal (Excl. Tax) internally means base_subtotal_with_discount (The label is kinda misleading 😃)