-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Ensure Quote::collectTotals() correctly handles recursion #36475
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
Conversation
Hi @fredden. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review. For more details, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket. ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
Not a Magento maintainer, but spotted this and I have worked on something similar before. What is the first thing to initiate collectTotals when you grab it from the session? Is it when it detects a currency code change? |
The stack trace / code paths that I'm looking at in this particular case are as follows. (I've taken all the interceptors out and removed lots of around* plug-ins which didn't seem relevant.)
The problem we were investigating is to do with gift cards being assigned to the quote on the first run (which is the inner call) and then being 'used up' by the time the totals are collected for that particular collector the second run (in the outer call). When there's only one call to I'm not aware of any currency code changes in this stack / process. Edit: I don't seem to have properly answered your question. Also, thanks for the link to the previous works; that's helpful.
This is the line of code that calls magento2/app/code/Magento/Checkout/Model/Session.php Lines 277 to 279 in 11846a1
So perhaps 29f0417 is where the regression was introduced. |
Ahhh interesting @fredden So this does not actually cause an infinite loo? just an additional call to Historically I have worked around this kind of thing by getting the quote from the plugin/event object rather than trying to grab it from the session, and it seems others have posted similar on stack exchange. Just in case you wanted to review alternate considerations |
In my opinion the quote model works ok.
If you need to recollect totals you can reset that via flag.
You can just extract quote id from
or other objects that available inside your plugin
and load from chace in Additionally |
@ilnytskyi & @convenient, would you suggest changing this to |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
@magento run Functional Tests CE, Functional Tests EE, Functional Tests B2B, Unit Tests, WebAPI Tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @fredden,
Failed tests seem flaky to me, and changes seem fine. Hence approving the PR.
Thanks
@magento create issue |
@magento run Functional Tests EE,Functional Tests B2B,Functional Tests CE,Unit Tests,WebAPI Tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
@magento run Functional Tests EE,Functional Tests B2B,Functional Tests CE |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
Hello @fredden, We are unable to reproduce the issue mentioned here. Please go through this comment #37856 (comment) and let us know in case we have missed anything. Meanwhile, we are putting this issue Thanks |
Hello @fredden, We are closing this PR for now as the original issue is not reproducible for us. Please go through with the comment here #37856 (comment). Feel free to reopen it and let us know if we have missed anything in order to reproduce the issue. Thanks |
Description
We have written a plug-in for a shipping method. Our plugin requires access the quote object to perform its business logic. We get a reference to the current quote object by calling
Magento\Checkout\Model\Session::getQuote()
. This works correctly and we get a reference to the quote object and can perform the required actions.Within
Magento\Checkout\Model\Session::getQuote()
, there is a call to$quote->collectTotals()
. When this runs via our plug-in, Magento ends up calling$quote->collectTotals()
within an existing call to$quote->collectTotals()
(recursion). This becomes a problem when we introduce gift cards, which is a feature of Adobe Commerce. Because we are applying the gift cards each time$quote->collectTotals()
is called, but the second time around the gift cards are already 'used', so they do not get applied to the$quote
, and therefore disappear from the checkout.Manual testing scenarios
Preconditions:
Magento\Checkout\Model\Session::getQuote()
Steps to reproduce:
Contribution checklist
Resolved issues: