Lately, I am trying to tweak Magento 2 Cart Price Rule feature for our business requirements and I realized something. First of all, I need to say that we override MagentoSalesRuleModelRuleConditionProductSubselect::loadAttributeOptions()
because in our location we must apply the discount on top of the tax included amount so we changed the ‘base_row_total’ with the ‘base_row_total_incl_tax’. Here is the scenario;
I have 2 Cart Price Rule;(₺ = currency)
- 50% discount for items in the cart, with cart condition; amount > 250₺, priority 0
- 20% discount for items in the cart, with cart condition; amount > 200₺, priority 1
I have a cart with 1 item with a total of 300₺ and let’s say that shipping is free. Our requirements say that; it should apply the first cart price rule and should not apply the second cart price rule because after applying the first cart price rule cart total is going down to 150₺ thus second cart price rule’s condition is not met from now on.
If we go back to the reality Magento validates conditions by the product’s attributes; Magento always looks for the same value, not the discounted fresh value.
MagentoSalesRuleModelRuleConditionProduct::validate($model)
declares that;
$total += ($hasValidChild && $useChildrenTotal) ?
$childrenAttrTotal * $item->getQty() : $item->getData($attr);
// $attr value is "base_row_total_incl_tax" for our case, and it does not change after every rule process step
return $this->validateAttribute($total); // this func just makes a logical comparison with boolean return
So, what do you think about this topic? Has anyone thought about it, should I just change the $total
with the latest discount applied cart amount(using registry) or does anyone have a better idea?