Skip to content

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

Open
@steven-hoffman-jomashop

Description

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.
  • 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”.

Metadata

Assignees

No one assigned

    Labels

    Area: OrderComponent: QuoteIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: ready for devReported on 2.4.7Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    • Status

      Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions