Skip to content

Commit

Permalink
Keep the billing credentials in local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
royduin committed Dec 13, 2021
1 parent e1caf91 commit 7fb81af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
12 changes: 9 additions & 3 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ document.addEventListener('turbolinks:load', () => {
'firstname': localStorage.shipping_firstname ?? (window.debug ? 'Bruce' : ''),
'lastname': localStorage.shipping_lastname ?? (window.debug ? 'Wayne' : ''),
'postcode': localStorage.shipping_postcode ?? (window.debug ? '72000' : ''),
'street': localStorage.shipping_street?.split(',') ?? (window.debug ? ['Mountain Drive', 1007] : []),
'street': localStorage.shipping_street?.split(',') ?? (window.debug ? ['Mountain Drive', 1007, ''] : ['', '', '']),
'city': localStorage.shipping_city ?? (window.debug ? 'Gotham' : ''),
'telephone': localStorage.shipping_telephone ?? (window.debug ? '530-7972' : ''),
'country_id': localStorage.shipping_country_id ?? (window.debug ? 'TR' : ''),
},
billing_address: {
'street': [],
'firstname': localStorage.billing_firstname ?? (window.debug ? 'Bruce' : ''),
'lastname': localStorage.billing_lastname ?? (window.debug ? 'Wayne' : ''),
'postcode': localStorage.billing_postcode ?? (window.debug ? '72000' : ''),
'street': localStorage.billing_street?.split(',') ?? (window.debug ? ['Mountain Drive', 1007, ''] : ['', '', '']),
'city': localStorage.billing_city ?? (window.debug ? 'Gotham' : ''),
'telephone': localStorage.billing_telephone ?? (window.debug ? '530-7972' : ''),
'country_id': localStorage.billing_country_id ?? (window.debug ? 'TR' : ''),
},
hide_billing: true,
hide_billing: localStorage.hide_billing === 'false' ? false : true,

totals: {},

Expand Down
27 changes: 16 additions & 11 deletions resources/js/components/Checkout/Checkout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,18 @@
return address
},
storeShipping() {
this.getShippingKeys().forEach((key) => {
let value = this.checkout.shipping_address[key]
let cacheKey = 'shipping_' + key
storeCredentials(type) {
Object.keys(this.checkout[type + '_address']).forEach((key) => {
let value = this.checkout.[type + '_address'][key]
let storageKey = type + '_' + key
if (value !== '') {
localStorage[cacheKey] = value
localStorage[storageKey] = value
} else {
localStorage.removeItem(cacheKey);
localStorage.removeItem(storageKey);
}
})
},
getShippingKeys() {
return Object.keys(this.checkout.shipping_address)
},
setupHistory() {
window.addEventListener('hashchange', () => {
this.backEvent = true
Expand Down Expand Up @@ -288,9 +284,18 @@
'checkout.shipping_address': {
deep: true,
handler: function() {
this.storeShipping()
this.storeCredentials('shipping')
}
},
'checkout.billing_address': {
deep: true,
handler: function() {
this.storeCredentials('billing')
}
},
'checkout.hide_billing': function (value) {
localStorage.hide_billing = value
},
'checkout.payment_method': function () {
this.selectPaymentMethod()
},
Expand Down

0 comments on commit 7fb81af

Please sign in to comment.