Description
Preconditions (*)
- Magento 2.3.4
- PHP 7.1+
- Create a cart price rule for a fixed amount for the whole cart (e.g. $1). The rule should have no conditions attached to it (or restrictions on the items it applies to)
- Create at least one configurable product with at least one simple product attached to each configurable.
- Set the price of each item to be $10 (actual price doesn't matter - just used $10 for example)
Steps to reproduce (*)
- Navigate to PDP of configurable product
- Select options for the configurable and add to cart
Expected result (*)
- Item is added to cart
- Cart total is $9 ($10 for item - $1 discount)
Actual result (*)
- Item is added to cart
- Cart total is $9.50 ($10 for item - $0.50 discount)
Notes
The issue is also present any time a new simple product is added to the cart. For example, if a different configurable option was chosen, the discount would be calculated as $0.67 (then $0.75 for another). The reason for this behaviour is due to the following:
When a configurable is added to the cart, two items actually get added as Quote items - the configurable, and the simple item representing the selected options.
As part of the rule calculation, it skips child (simple) items by checking the result of getParentItemId()
:
magento2/app/code/Magento/SalesRule/Model/Validator.php
Lines 385 to 388 in e6e6725
However, for a newly added item, parentItemId
is not set yet, as this is only set in the beforeSave
function of the quote item:
magento2/app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php
Lines 178 to 185 in e6e6725
Instead, the Validator
class should be checking the result of getParentItem