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
- Create a cart rule with following
- {{{}Conditions{}}}:
Subtotal (Excl. Tax)is equals or greater than100 - {{{}Actions{}}}:
Free Shipping=For matching items only
- Create another cart rule with coupon
XYZto give aFixed amount discount for whole cartof10
Storefront
- Add items to the cart to make a subtotal of 105
- Apply the coupon
XYZto 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
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)
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
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 meansbase_subtotal_with_discount(The label is kinda misleading 😃)