cart rule condition based on price including tax
-
15-04-2021 - |
Question
I want to create a rule that gives people a discount of 10% if the subtotal of the cart is over $100.
I have this rule working but with one problem, to check weather the cart is over $100 it is using the subtotal without tax were I want it to use the subtotal with tax.
The condition I am using is pictured below.
I have looked into changing Configuration -> Sales -> Tax settings but most of these settings are already set how I need them for the rest of the site. There are also some products with and without tax so I cannot try and cheat my way by using a lower number.
Solution
Same issue with magento 2.2.2.
When you create a cart rule and you select Subtotal as cart attribute condition you are choosing the html option value value="Magento\SalesRule\Model\Rule\Condition\Address|base_subtotal"
.
It means that the cart rule will use the quote_address.base_subtotal
column to validate the coupon's condition.
If your catalog has the Catalog Prices option (Stores->Configuration->Sales->Tax->Calculation Settings) setted to Excluding Tax the quote_address.base_subtotal
will contain subtotal WITHOUT tax.
Now, digging in the magento core i found that the cart rule condition is validated in vendor/magento/module-rule/Model/Condition/AbstractCondition.php
with validate()
method.
To fix the issue, i changed the code in
...
$attr = $this->getAttribute();
if ($attr == "base_subtotal") $attr = "base_subtotal_total_incl_tax";
$attributeValue = $model->getData($attr);
return $this->validateAttribute($attributeValue);
...
so, quote_address.base_subtotal_total_incl_tax
will be used instead of quote_address.base_subtotal
.
PS1: i also tried a lot on the web to find a solution and i did not find anything
PS2: i changed and suggested how to fix the issue directly in the core file, but it is a bad pratice, take your precautions :)
OTHER TIPS
This is is fixed by patch MDVA-31399. If you apply this patch it gives a new discount condition "Subtotal (Incl. Tax)", which explicitly includes tax when triggering discounts.
The problem is discussed on the GitHub issue tracker here: https://github.com/magento/magento2/issues/29740 Suggests that it will be available in 2.3.7 which has not been released at the time of answering this question.