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.35k stars 9.27k forks source link

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

Open steven-hoffman-jomashop opened 4 weeks ago

steven-hoffman-jomashop commented 4 weeks ago

Preconditions and environment

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

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

m2-assistant[bot] commented 4 weeks ago

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:

m2-assistant[bot] commented 1 day 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 day ago

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

github-jira-sync-bot commented 1 day ago

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

m2-assistant[bot] commented 1 day ago

: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.