PayPal - Express Checkout returnFromPaypal copies cached address items from shipping to billing #38776
Open
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
- Create a quote
- Add an non virtual item to the cart
- Modify the sample code below to use the quote id created above
- 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
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
Labels
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmedMay be fixed according to the position in the backlog.Indicates original Magento version for the Issue report.The issue has been reproduced on latest 2.4-develop branchIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
Type
Projects
Status
Ready for Development