feat: make carts pesistent across stores

This commit is contained in:
Tiago Vasconcelos 2023-03-17 11:11:23 +00:00
parent 14cea467a8
commit 68e503df63

View file

@ -86,7 +86,6 @@ async function customerStall(path) {
return LNbits.utils.formatCurrency(amount, unit) return LNbits.utils.formatCurrency(amount, unit)
}, },
addToCart(item) { addToCart(item) {
console.log('add to cart', item)
let prod = this.cart.products let prod = this.cart.products
if (prod.has(item.id)) { if (prod.has(item.id)) {
let qty = prod.get(item.id).quantity let qty = prod.get(item.id).quantity
@ -115,7 +114,6 @@ async function customerStall(path) {
this.updateCart(+item.price, true) this.updateCart(+item.price, true)
}, },
updateCart(price, del = false) { updateCart(price, del = false) {
console.log(this.cart, this.cartMenu)
if (del) { if (del) {
this.cart.total -= price this.cart.total -= price
this.cart.size-- this.cart.size--
@ -126,7 +124,10 @@ async function customerStall(path) {
this.cartMenu = Array.from(this.cart.products, item => { this.cartMenu = Array.from(this.cart.products, item => {
return {id: item[0], ...item[1]} return {id: item[0], ...item[1]}
}) })
console.log(this.cart, this.cartMenu) this.$q.localStorage.set(`diagonAlley.carts.${this.stall.id}`, {
...this.cart,
products: Object.fromEntries(this.cart.products)
})
}, },
resetCart() { resetCart() {
this.cart = { this.cart = {
@ -134,6 +135,7 @@ async function customerStall(path) {
size: 0, size: 0,
products: new Map() products: new Map()
} }
this.$q.localStorage.remove(`diagonAlley.carts.${this.stall.id}`)
}, },
async downloadOrder() { async downloadOrder() {
let created_at = Math.floor(Date.now() / 1000) let created_at = Math.floor(Date.now() / 1000)
@ -372,6 +374,18 @@ async function customerStall(path) {
this.customerPubkey = this.account?.pubkey this.customerPubkey = this.account?.pubkey
this.customerPrivkey = this.account?.privkey this.customerPrivkey = this.account?.privkey
this.customerUseExtension = this.account?.useExtension this.customerUseExtension = this.account?.useExtension
let storedCart = this.$q.localStorage.getItem(
`diagonAlley.carts.${this.stall.id}`
)
if (storedCart) {
this.cart.total = storedCart.total
this.cart.size = storedCart.size
this.cart.products = new Map(Object.entries(storedCart.products))
this.cartMenu = Array.from(this.cart.products, item => {
return {id: item[0], ...item[1]}
})
}
setTimeout(() => { setTimeout(() => {
if (window.nostr) { if (window.nostr) {
this.hasNip07 = true this.hasNip07 = true