vuestorefront / vue-storefront-1

The open-source frontend for any eCommerce. Built with a PWA and headless approach, using a modern JS stack. We have custom integrations with Magento, commercetools, Shopware and Shopify and total coverage is just a matter of time. The API approach also allows you to merge VSF with any third-party tool like CMS, payment gateways or analytics. Newest updates: https://blog.vuestorefront.io. Always Open Source, MIT license.
https://www.vuestorefront.io
MIT License
19 stars 13 forks source link

Offline: Shipping amount not added up in totals in the offline mode #173

Closed bloodf closed 3 years ago

bloodf commented 3 years ago

From vue-storefront created by ymaheshwari1: vuestorefront/vue-storefront#5024

Current behavior

When we are offline, then on the checkout page the shipping amount is not displayed and the shipping amount is also not added up in the Totals. But after placing the order in offline mode and if the order is confirmed then the amount is added up in the totals.

Expected behavior

The shipping amount should be displayed in the price summary section on the checkout page. The total also needs to be updated as the shipping amount changes.

Steps to reproduce the issue

  1. Go offline
  2. Go to checkout
  3. Here you can see the shipping amount is not displayed.
  4. Select a shipping method having some shipping amount associated with it.
  5. See that the total is not updated.

Version of Vue Storefront

Can you handle fixing this bug by yourself?

Which Release Cycle state this refers to? Info for developer. (doesn't apply to Next)

Pick one option.

Environment details

Additional information

bloodf commented 3 years ago

While debugging the issue, found the following points:

  1. For doing the calculations in the offline mode we are using the calculateTotals method.
    • In the calculateTotals method, the shipping method is always undefined, because we are assigning the state.shipping of the cart with checkout/getDefaultShippingMethod (methodActions.ts) and we are passing getFirstShippingMethod getter in calculateTotals method which is 0th index of state.shipping and thus the value is undefined.
    • For the above issue, the solution can be either to pass getShippingMethod getter to the calculateTotals or to allocate checkout/getShippingMethods to the state.shipping (methodActions.ts).
  2. When the shipping method is changed in offline mode then the calculateTotals() is not called again, as after changing the shipping Method, syncTotals action is dispatched which then calls API to fetch the totals from the server.
    • To solve the above issue, we can apply an offline condition in the syncTotals action and then again call the calculateTotals method from there.
    • When using the above solution the price section is not updating, because the section only updates when the platformTotalSegments state is updated. Thus, committing a mutation to update the platormTotalSegements so that the price section gets updated. After doing the mentioned things, then also the shipping and the grand_total are properly synced in offline mode.

Also, for calculating the shippingTax in the offline we are using price_incl_tax key, which is always 0 and the actual shipping amount is in the amount key.