Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 60 additions & 22 deletions app/code/Magento/Checkout/view/frontend/web/js/checkout-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,40 @@ define([
'use strict';

var cacheKey = 'checkout-data',
checkoutData,

/**
* @param {Object} data
* @return {*}
*/
saveData = function (data) {
storage.set(cacheKey, data);
getData = function () {
return storage.get(cacheKey)();
},

/**
* @return {*}
* @param {Object} data
*/
getData = function () {
var data = storage.get(cacheKey)();

if ($.isEmptyObject(data)) {
data = {
'selectedShippingAddress': null,
'shippingAddressFromData': null,
'newCustomerShippingAddress': null,
'selectedShippingRate': null,
'selectedPaymentMethod': null,
'selectedBillingAddress': null,
'billingAddressFormData': null,
'newCustomerBillingAddress': null
};
saveData(data);
}

return data;
saveData = function (data) {
storage.set(cacheKey, data);
};

if ($.isEmptyObject(getData())) {
checkoutData = {
'selectedShippingAddress': null, //Selected shipping address pulled from persistence storage.
'shippingAddressFromData': null, //Shipping address pulled from persistence storage.
'newCustomerShippingAddress': null, //Shipping address pulled from persistence storage for new customer.
'selectedShippingRate': null, //Shipping rate pulled from persistence storage.
'selectedPaymentMethod': null, //Payment method pulled from persistence storage.
'selectedBillingAddress': null, //Selected billing address pulled from persistence storage.
'billingAddressFromData': null, //Billing address pulled from persistence storage.
'newCustomerBillingAddress': null //Billing address pulled from persistence storage for new customer.
};
saveData(checkoutData);
}

return {
/**
* Setting the selected shipping address pulled from persistence storage.
*
* @param {Object} data
*/
setSelectedShippingAddress: function (data) {
Expand All @@ -58,13 +59,17 @@ define([
},

/**
* Pulling the selected shipping address from persistence storage.
*
* @return {*}
*/
getSelectedShippingAddress: function () {
return getData().selectedShippingAddress;
},

/**
* Setting the shipping address pulled from persistence storage.
*
* @param {Object} data
*/
setShippingAddressFromData: function (data) {
Expand All @@ -75,13 +80,17 @@ define([
},

/**
* Pulling the shipping address from persistence storage.
*
* @return {*}
*/
getShippingAddressFromData: function () {
return getData().shippingAddressFromData;
},

/**
* Setting the shipping address pulled from persistence storage for new customer.
*
* @param {Object} data
*/
setNewCustomerShippingAddress: function (data) {
Expand All @@ -92,13 +101,17 @@ define([
},

/**
* Pulling the shipping address from persistence storage for new customer.
*
* @return {*}
*/
getNewCustomerShippingAddress: function () {
return getData().newCustomerShippingAddress;
},

/**
* Setting the selected shipping rate pulled from persistence storage.
*
* @param {Object} data
*/
setSelectedShippingRate: function (data) {
Expand All @@ -109,13 +122,17 @@ define([
},

/**
* Pulling the selected shipping rate from local storge
*
* @return {*}
*/
getSelectedShippingRate: function () {
return getData().selectedShippingRate;
},

/**
* Setting the selected payment method pulled from persistence storage.
*
* @param {Object} data
*/
setSelectedPaymentMethod: function (data) {
Expand All @@ -126,13 +143,17 @@ define([
},

/**
* Pulling the payment method from persistence storage.
*
* @return {*}
*/
getSelectedPaymentMethod: function () {
return getData().selectedPaymentMethod;
},

/**
* Setting the selected billing address pulled from persistence storage.
*
* @param {Object} data
*/
setSelectedBillingAddress: function (data) {
Expand All @@ -143,13 +164,17 @@ define([
},

/**
* Pulling the selected billing address from persistence storage.
*
* @return {*}
*/
getSelectedBillingAddress: function () {
return getData().selectedBillingAddress;
},

/**
* Setting the billing address pulled from persistence storage.
*
* @param {Object} data
*/
setBillingAddressFromData: function (data) {
Expand All @@ -160,13 +185,16 @@ define([
},

/**
* Pulling the billing address from persistence storage.
* @return {*}
*/
getBillingAddressFromData: function () {
return getData().billingAddressFromData;
},

/**
* Setting the billing address pulled from persistence storage for new customer.
*
* @param {Object} data
*/
setNewCustomerBillingAddress: function (data) {
Expand All @@ -177,13 +205,17 @@ define([
},

/**
* Pulling the billing address from persistence storage for new customer.
*
* @return {*}
*/
getNewCustomerBillingAddress: function () {
return getData().newCustomerBillingAddress;
},

/**
* Pulling the email address from persistence storage.
*
* @return {*}
*/
getValidatedEmailValue: function () {
Expand All @@ -193,6 +225,8 @@ define([
},

/**
* Setting the email address pulled from persistence storage.
*
* @param {String} email
*/
setValidatedEmailValue: function (email) {
Expand All @@ -203,6 +237,8 @@ define([
},

/**
* Pulling the email input field value from persistence storage.
*
* @return {*}
*/
getInputFieldEmailValue: function () {
Expand All @@ -212,6 +248,8 @@ define([
},

/**
* Setting the email input field value pulled from persistence storage.
*
* @param {String} email
*/
setInputFieldEmailValue: function (email) {
Expand Down