We have the following situation in Magento:
-
Guest customer is about place order.
-
The customer filled his billing and shipping addresses on checkout page.
-
The customer reached one of the following checkout steps (shipping methods, payment methods, order review).
-
The customer decides to edit his cart and goes back to cart page
-
The customer reaches the checkout page again then billing information should display
How can store and retrieve the customer information
Best Answer
You can use various local storage mechanisms to store this data in the browser such as Web Storage.
The simplest and most widely supported is WebStorage where you have persistent storage (localStorage) or session based (sessionStorage) which is in memory until you close the browser. Both share the same API.
You can for example (simplified) do something like this when the page is about to reload:
Web Storage works synchronously so this can work here. Optionally you can store the data for each blur event on the elements where the data is entered.
At page load you can check:
getItem
returnsnull
if the data does not exist.Use
sessionStorage
instead oflocalStorage
if you want to store only temporary.For More See here.