Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed cart discount calculated incorrectly when product first added to cart. #26622

Closed
aligent-lturner opened this issue Feb 1, 2020 · 10 comments
Assignees
Labels
Component: Quote Component: SalesRule Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Progress: PR Created Indicates that Pull Request has been created to fix issue Reported on 2.3.4 Indicates original Magento version for the Issue report. Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@aligent-lturner
Copy link
Contributor

Preconditions (*)

  1. Magento 2.3.4
  2. PHP 7.1+
  3. 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)
  4. Create at least one configurable product with at least one simple product attached to each configurable.
  5. Set the price of each item to be $10 (actual price doesn't matter - just used $10 for example)

Steps to reproduce (*)

  1. Navigate to PDP of configurable product
  2. Select options for the configurable and add to cart

Expected result (*)

  1. Item is added to cart
  2. Cart total is $9 ($10 for item - $1 discount)

Actual result (*)

  1. Item is added to cart
  2. 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():

//Skipping child items to avoid double calculations
if ($item->getParentItemId()) {
continue;
}

However, for a newly added item, parentItemId is not set yet, as this is only set in the beforeSave function of the quote item:

public function beforeSave()
{
parent::beforeSave();
if ($this->getParentItem()) {
$this->setParentItemId($this->getParentItem()->getId());
}
return $this;
}

Instead, the Validator class should be checking the result of getParentItem

@magento-deployment-service
Copy link

Thanks for opening this issue!

@m2-assistant
Copy link

m2-assistant bot commented Feb 1, 2020

Hi @aligent-lturner. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@aligent-lturner do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Feb 1, 2020
aligent-lturner added a commit to aligent-lturner/magento2-1 that referenced this issue Feb 1, 2020
…Id, as the latter is only set in beforeSave function.
@ghost ghost assigned aligent-lturner Feb 1, 2020
@aligent-lturner
Copy link
Contributor Author

@magento give me 2.4-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @aligent-lturner. Thank you for your request. I'm working on Magento 2.4-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @aligent-lturner, here is your Magento instance.
Admin access: https://i-26622-2-4-develop.instances.magento-community.engineering/admin_9f98
Login: 277ecaa4 Password: ef4621a07619
Instance will be terminated in up to 3 hours.

@aligent-lturner
Copy link
Contributor Author

Luma does not display discounts in minicart, and I do not have access to the underlying database to confirm the issue in the provided vanilla instance.

@aligent-lturner
Copy link
Contributor Author

Actually - I was able to use the database backup functionality to confirm the issue in vanilla instance:

From quote table, after adding 2 $10 items:

INSERT INTO `quote` VALUES ('1',1,'2020-02-01 02:13:05','2020-02-01 02:17:19',NULL,1,0,0,'2','2.0000','0','0.0000','0.0000','USD','USD','USD','19.3300','19.3300',NULL,NULL,'3','0',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,'180.150.113.242','1',NULL,NULL,NULL,'USD','1.0000','1.0000',NULL,NULL,'20.0000','20.0000','19.3300','19.3300','1',0,NULL,NULL,0);

Note the values $19.33 (i.e. a discount of $0.67 has been applied, rather than $1)

And from the quote_item table:

INSERT INTO `quote_item` VALUES ('3','1','2020-02-01 02:15:23','2020-02-01 02:17:19','3',1,NULL,0,'Test_Product-Blue','Test Product',NULL,'1',NULL,0,0,'1.0000','1.0000','10.0000','10.0000',NULL,'0.0000','0.3300','0.3300','0.0000','0.0000','0.0000','10.0000','10.0000','0.0000','1.0000','configurable',NULL,NULL,NULL,NULL,NULL,'10.0000','10.0000','10.0000','10.0000','0.0000','0.0000',NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),('4','1','2020-02-01 02:15:23','2020-02-01 02:15:23','1',1,'3',0,'Test_Product-Blue','Test Product-Blue',NULL,NULL,NULL,0,0,'1.0000','1.0000','10.0000','0.0000',NULL,'0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','simple',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),('5','1','2020-02-01 02:17:19','2020-02-01 02:17:19','3',1,NULL,0,'Test_Product-Red','Test Product',NULL,'1',NULL,0,0,'1.0000','1.0000','10.0000','10.0000',NULL,'0.0000','0.3400','0.3400','0.0000','0.0000','0.0000','10.0000','10.0000','0.0000','1.0000','configurable',NULL,NULL,NULL,NULL,NULL,'10.0000','10.0000','10.0000','10.0000','0.0000','0.0000',NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),('6','1','2020-02-01 02:17:19','2020-02-01 02:17:19','2',1,'5',0,'Test_Product-Red','Test Product-Red',NULL,NULL,NULL,0,0,'1.0000','1.0000','10.0000','0.0000',NULL,'0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','0.0000','simple',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);

Here, we can see discounts for the 2 items of $0.33 and $0.34 instead of $0.50 for each.

@shikhamis11 shikhamis11 self-assigned this Feb 2, 2020
@m2-assistant
Copy link

m2-assistant bot commented Feb 2, 2020

Hi @shikhamis11. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@aligent-lturner aligent-lturner added Component: Quote Component: SalesRule Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Feb 4, 2020
@ghost ghost removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Feb 4, 2020
@ghost
Copy link

ghost commented Feb 4, 2020

✅ Confirmed by @aligent-lturner
Thank you for verifying the issue! 👍 Your confirmation will help us to acknowledge and process this report.

@ghost ghost assigned aligent-lturner Feb 4, 2020
@aligent-lturner aligent-lturner added Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Progress: PR Created Indicates that Pull Request has been created to fix issue labels Feb 4, 2020
aligent-lturner added a commit to aligent-lturner/magento2-1 that referenced this issue Feb 4, 2020
aligent-lturner added a commit to aligent-lturner/magento2-1 that referenced this issue Feb 4, 2020
aligent-lturner added a commit to aligent-lturner/magento2-1 that referenced this issue Feb 5, 2020
aligent-lturner added a commit to aligent-lturner/magento2-1 that referenced this issue Feb 5, 2020
aligent-lturner added a commit to aligent-lturner/magento2-1 that referenced this issue Feb 5, 2020
aligent-lturner added a commit to aligent-lturner/magento2-1 that referenced this issue Feb 6, 2020
aligent-lturner added a commit to aligent-lturner/magento2-1 that referenced this issue Feb 6, 2020
@slavvka slavvka added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Feb 9, 2020
@slavvka slavvka closed this as completed Feb 9, 2020
magento-engcom-team added a commit that referenced this issue Feb 9, 2020
…ntItemId #26623

 - Merge Pull Request #26623 from aligent-lturner/magento2-1:fix/GH26622_fixed_amount_discount
 - Merged commits:
   1. e943bda
   2. 199afbf
   3. 90c3540
   4. 5f4cc5f
   5. 0e9c4ef
   6. 2c961af
   7. 75b03e0
   8. a037edf
@magento-engcom-team magento-engcom-team added the Reported on 2.3.4 Indicates original Magento version for the Issue report. label Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Quote Component: SalesRule Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Progress: PR Created Indicates that Pull Request has been created to fix issue Reported on 2.3.4 Indicates original Magento version for the Issue report. Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
None yet
Development

No branches or pull requests

4 participants