Closed Tomasito665 closed 2 months ago
Hi @Tomasito665. 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:
@magento give me 2.4-develop instance
- upcoming 2.4.x release@magento I am working on this
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.
Hi @engcom-Dash. 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:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.I found the issue. The instant purchase PlaceOrder::placeOrder() method:
So far, so good. However, if we take a closer look at QuoteCreation::createQuote, we see that it assigns the shipping and billing address to the quote, but does not flag them for rate recalculation before totals collection, i.e., does not call setCollectShippingRates(true) before Quote::collectTotals(). It does so, but further down the pipeline when choosing the cheapest method—after having collected the totals already.
If we set setCollectShippingRates(true) before Quote::collectTotals(), then shipping rates are collected correctly as part of the "collect totals" operation. Diving into the code that calculates quote address totals, we see that it sets some "magic" fields immediately before collecting shipping rates.
Take the "item qty" field. The abovementioned code snippet computes the number of "sendable" items and assigns that value to the address "item qty" field. I call this a "magic" field because it is never persisted in the database. Its only purpose, as far as I can tell, is to provide a way to override the return value of Address::getItemQty, which would normally "simply" return the sum of the item quantities, regardless of whether those are sendable.
This is what makes shipping rate calculation work when called within the context of collecting totals. It overrides the address item quantity with the "sendable" quantity, which is the correct quantity in the context of computing shipping rates. With instant purchase, however, the sendable quantity is not set, and rates are computed incorrectly when choosing "cheapest shipping." In summary:
The correct shipping rates are correctly computed as part of the call to Quote::collectTotals() but not retained as the "collect shipping rates" flags are not set at that point.
The CheapestMethodDeferredChooser sets the "collect shipping rates" flags and calls collectShippingRates()
to compute the shipping rates. However, it does not specify the "sendable" items when doing so, and rates are computed incorrectly.
As a straightforward solution, I propose to:
Hi,
Internal team has started to work on it
Thanks
As the internal team has started working on it, we are moving this issue to on hold
until we receive further updates. We will provide updates on this issue as they become available.
Hello,
As I can see this issue got fixed in the scope of the internal Jira ticket AC-12119 by the internal team Related commits: https://github.com/search?q=repo%3Amagento%2Fmagento2+AC-12119-v1&type=commits
Thanks.
Preconditions and environment
(1) Install magento
Do a composer-based installation of magento 2.4.7. We need the magento/inventory modules for in-store delivery, which are not part of the core magento repository but are automaticallMore colorsy included for composer-based installations.
Deploy sample data into your Magento installation. The steps described in this issue assume this sample data to be installed. See https://github.com/magento/magento2-sample-data for more info.
Install the [magento-instant-purchase-mock](https://github.com/Tomasito665/magento-instant-purchase-mock/tree/main] extension. This extension was designed specifically for this issue and does minimal surgical changes to magento's
InstantPurchase
module to enable theInstant Purchase
button without installing and configuring [Payment Services|https://experienceleague.adobe.com/en/docs/commerce-merchant-services/payment-services/guide-overview] or [Braintree|https://experienceleague.adobe.com/en/docs/commerce-admin/stores-sales/payments/braintree), which is normally required for enabling instant purchase functionality but is not necessary for the demonstration of this bug.(2) Set up in-store delivery
Enable in-store pickup
Create in-store pickup source
Create in-store pickup stock
(3) Enable products for in-store pickup
Assign simple product to ISPU source
Assign configurable product to ISPU source
(4) Configure flat rate as the cheapest option
(5) Create a customer account
On the frontend page, click on Create an Account to create a customer account.
Once logged in, go to My Account → Address Book → Default Billing Address.
Click on Edit Address and fill in the following.
Make sure that the address appears both as:
Log out and log in again to refresh instant purchase options.
(6) Verify that in-store delivery is available
(7) Verify that instant purchase is available
Instant Purchase
button renders. If it does not, make sure that the Magento_InstantPurchaseMock module is correctly installed and enabled as described in step 1. Also, theInstant Purchase
button only renders if you are logged in as a customer and if that customer has both a default billing and a default shipping address. Make sure these addresses are properly configured as described in step 5.Steps to reproduce
Expected result
The order is placed using the cheapest shipment method, which, as we saw in step 6, is the $5.00 Flat Rate shipment method.
<img width="1124" alt="Expected behavior" src="https://github.com/magento/magento2/assets/12563382/541e573b-0e3a-4174-b066-1f1c4f99160f"]
Actual result
The order is placed using the $6.00 In-Store Delivery shipment method, which is NOT the cheapest shipment method. {quote}[!NOTE] {quote} {quote}As seen in the screenshot, with my setup, the order placement does not finish successfully and ends with a "Quote does not have Pickup Location assigned" error. The cause of this error is irrelevant to the bug described in this issue. However, the fact that it gives this error in particular shows that the instant purchase flow attempts to place the order using the In-Store Delivery shipment method, which is sufficient to demonstrate the bug. {quote} [img width="1136" alt="ActualBehavior_2of2" src="https://github.com/magento/magento2/assets/12563382/bce0144a-5faf-4f2e-9487-4da90f8315df">
Additional information
It works for simple products
Flat rate counted double for configurable products 🐛
The "cheapest price" shipment method is calculated in the CheapestMethodDeferredChooser class in the following method. The $5.00 Flat Rate shipping is not correctly identified as the cheapest option because, for reasons unclear to me, its price is doubled when performing the comparison to the $6.00 In-Store Delivery. <https://github.com/magento/magento2/blob/001e5188cd59309f5de9205946ede5ddccdadaff/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php#L35-L50]
When debugging the instant purchase of the Joust Duffle Bag simple product, we see that the
$shippingRates
array contains the following rates.``{{javascript [ {_data:
"magento/product-community-edition": "2.4.7"