magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

[Issue] Ensure Quote::collectTotals() correctly handles recursion #37856

Open m2-assistant[bot] opened 1 year ago

m2-assistant[bot] commented 1 year ago

This issue is automatically created based on existing pull request: magento/magento2#36475: Ensure Quote::collectTotals() correctly handles recursion


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:

Steps to reproduce:

  1. Add items to cart to ensure cart total is more than available balance on gift card
  2. Apply gift card at cart
  3. Proceed to payment step in checkout
  4. Notice gift card is applied correctly
  5. Select payment method multiple times
  6. Notice gift card is (not) applied correctly

Contribution checklist

m2-assistant[bot] commented 1 year ago

Hi @engcom-Hotel. 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: :point_down:

engcom-Hotel commented 1 year ago

Hello @fredden,

Thanks for the report and collaboration!

We have tried to reproduce the issue in Magento 2.4-develop branch but it seems the issue is not reproducible for us.

We have tried to follow the steps mentioned in the main description. For reference, we are attaching the plugin made by us in order to reproduce the issue. Magz.zip

We have made after plugin on Magento\Quote\Model\Quote, and for us Gift Card is applying correctly.

Gift Card image

Checkout Page image

Let us know in case we have missed anything.

Thanks