avarda-ab / Magento2-Checkout-module

Avarda Checkout2 payment module for Magento 2
1 stars 0 forks source link

Checkout TotalPrice is counting shipping price twice #9

Closed GrzegorzKrauze closed 3 months ago

GrzegorzKrauze commented 3 months ago

Using shipping broker as a delivery method source.

Scenario:

  1. not logged in user is adding one (or more) product into the new cart -> a new guest cart is created with this product as a item

  2. user goes to the cart, and goes to the avarda checkout -> user can see shipping methods. There is also a items call: https://stage.checkout-api.avarda.com/api/partner/payments/{purchaseid}/items . It adds the selected product as a item in given purchaseId in Avarda

  3. update request is called -> Avarda API is sending request for update and it receives the correct amount in TotalPrice, which is "subtotal" + "selected shipping method price"

  4. User refreshes the checkout -> The items are sent again to avarda but this time the qoute shipping is added as a item.

  5. In result on the update request, the selected shipping price is added twice.

When I patched the code not to add a shipping as a item in the quote then it is working as expected: -> when the shipping is already chosen and the user is refreshing the page - the amount is not increased by the additional shipping cost -> when placing the order the "shipping item" is added.

My patch only commented this line as a workaround:

Referring this line https://github.com/avarda-ab/Magento2-Checkout-module/blame/3c99643f1b20a053c7240ac8b91cab1416dfaff0/Plugin/Model/Quote/QuoteCollectTotalsPrepareItems.php#L179

Is it necessary to add the "shipping item" from the cart shipping address in any case?

GrzegorzKrauze commented 3 months ago

In other words the difference is on enter the checkout page, when the module is sending

PUT https://stage.checkout-api.avarda.com/api/partner/payments/{purchaseid}/items
  1. If user is refreshing (or getting back to) the checkout page - the "shipping item" is added here
  2. If the user is entering the checkout page the first time - only the product items are added to avarda with this PUT request

after the "1 point" scenario the "update" request to avarda is adding a selected shipping on top of already added items. So if you added one product and entered the checkout module twice you have 3 items in avarda purchase, from which 2 are shippings. after the "2 point" scenario the "upfate" request is also adding a shipping method item but there is no extra item here.

Of course this is the case on the shipping broker variant. I haven't had occasion to test it with the regular magento-defined delivery methods.

GrzegorzKrauze commented 3 months ago

I've moved it to the correct module version: https://github.com/avarda-ab/Magento-2-Checkout-3-module/issues/48