magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

PayPal - Express Checkout returnFromPaypal copies cached address items from shipping to billing

Open steven-hoffman-jomashop opened this issue 1 year ago • 5 comments

Preconditions and environment

  • 2.4.4 (Relevant code is the same on 2.4.7 - \Magento\Paypal\Model\Express\Checkout::returnFromPaypal)

Steps to reproduce

  1. Create a quote
  2. Add an non virtual item to the cart
  3. Modify the sample code below to use the quote id created above
  4. Run the sample code below
    • Alternatively, you can call into \Magento\Paypal\Model\Express\Checkout::returnFromPaypal directly
    • Add a fixed price discount to a simple item
    • setPaymentMethodOnCart with paypal_express is enough; but you have to have a PayPal checkout session set up (Or stub out the relevant paypal calls)
    • Calling \Magento\QuoteGraphQl\Model\Cart\TotalsCollector::collectQuoteTotals via the GQL
      • setPaymentMethodOnCart(Paypal) -> cart -> prices -> cart -> subtotal_with_discount_excluding_tax
// Test
$quoteId = 1234;
$quoteRepository = $om->get(\Magento\Quote\Model\QuoteRepository::class);
$quote = $quoteRepository->get($quoteId);

$shippingAddress = $quote->getShippingAddress();
$allItemsAfterLoadShipping = $shippingAddress->getAllItems();
echo 'Items (Shipping) on load: ' . count($allItemsAfterLoadShipping) .PHP_EOL;
foreach ($allItemsAfterLoadShipping as $item){
    echo '- ItemId: ' . $item->getId().PHP_EOL;
 }

$billingAddress = $quote->getBillingAddress();
$allItemsAfterLoadBilling = $billingAddress->getAllItems();
echo 'Items (Billing)  on load: ' . count($allItemsAfterLoadBilling) .PHP_EOL;
foreach ($allItemsAfterLoadBilling as $item){
    echo '- ItemId: ' . $item->getId().PHP_EOL;
}

// Run code from \Magento\Paypal\Model\Express\Checkout::returnFromPaypal
echo PHP_EOL;
$this->codeFrom_returnFromPaypal($quote, $quote->getShippingAddress());


$shippingAddress = $quote->getShippingAddress();
$allItemsAfterLoadShipping = $shippingAddress->getAllItems();
echo 'Items (Shipping) after paypal logic: ' . count($allItemsAfterLoadShipping) .PHP_EOL;
foreach ($allItemsAfterLoadShipping as $item){
    echo '- ItemId: ' . $item->getId().PHP_EOL;
}

$billingAddress = $quote->getBillingAddress();
$allItemsAfterLoadBilling = $billingAddress->getAllItems();
echo 'Items (Billing)  after paypal logic: ' . count($allItemsAfterLoadBilling) .PHP_EOL;
foreach ($allItemsAfterLoadBilling as $item){
    echo '- ItemId: ' . $item->getId().PHP_EOL;
}

if($allItemsAfterLoadBilling[0] === $allItemsAfterLoadShipping[0]){
    echo 'Same item in billing address and shipping address'.PHP_EOL;
}

echo PHP_EOL . 'Ending' . PHP_EOL;

Expected result

Quote's billing address DOES NOT contain the same item as the shipping address

  • If testing via GQL as above, it should be observable that the subtotal_with_discount_excluding_tax value is incorrect (As discount is applied for the item both from the shipping address as well as the billing address most likely).

Actual result

Quote's billing address DOES contain the same item as the shipping address

Additional information

See: https://github.com/magento/magento2/blob/2.4.7/app/code/Magento/Paypal/Model/Express/Checkout.php#L659

Adding: $billingAddress->unsetData('cached_items_all'); after the clone appears sufficient to mitigate the issue. Also, subsequent GQL calls appear to return the correct data.

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [X] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

steven-hoffman-jomashop avatar May 29 '24 15:05 steven-hoffman-jomashop

Hi @steven-hoffman-jomashop. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues 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.

m2-assistant[bot] avatar May 29 '24 15:05 m2-assistant[bot]

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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas 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.

m2-assistant[bot] avatar Jun 25 '24 09:06 m2-assistant[bot]

Hello @steven-hoffman-jomashop,

Thanks for the report and collaboration!

We are able to reproduce this issue in the latest 2.4-develop branch, hence confirming the issue.

Thanks

engcom-Hotel avatar Jun 25 '24 09:06 engcom-Hotel

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12289 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Jun 25 '24 09:06 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Jun 25 '24 09:06 m2-assistant[bot]