From 68e503df638dc4107fbb1c348f29d73e3b23dea7 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Fri, 17 Mar 2023 11:11:23 +0000 Subject: [PATCH] feat: make carts pesistent across stores --- .../customer-stall/customer-stall.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/static/components/customer-stall/customer-stall.js b/static/components/customer-stall/customer-stall.js index 0b0bddb..f5e7239 100644 --- a/static/components/customer-stall/customer-stall.js +++ b/static/components/customer-stall/customer-stall.js @@ -86,7 +86,6 @@ async function customerStall(path) { return LNbits.utils.formatCurrency(amount, unit) }, addToCart(item) { - console.log('add to cart', item) let prod = this.cart.products if (prod.has(item.id)) { let qty = prod.get(item.id).quantity @@ -115,7 +114,6 @@ async function customerStall(path) { this.updateCart(+item.price, true) }, updateCart(price, del = false) { - console.log(this.cart, this.cartMenu) if (del) { this.cart.total -= price this.cart.size-- @@ -126,7 +124,10 @@ async function customerStall(path) { this.cartMenu = Array.from(this.cart.products, item => { 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() { this.cart = { @@ -134,6 +135,7 @@ async function customerStall(path) { size: 0, products: new Map() } + this.$q.localStorage.remove(`diagonAlley.carts.${this.stall.id}`) }, async downloadOrder() { let created_at = Math.floor(Date.now() / 1000) @@ -372,6 +374,18 @@ async function customerStall(path) { this.customerPubkey = this.account?.pubkey this.customerPrivkey = this.account?.privkey 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(() => { if (window.nostr) { this.hasNip07 = true