diff --git a/static/components/customer-stall/customer-stall.js b/static/components/customer-stall/customer-stall.js index cb3e729..a39fccb 100644 --- a/static/components/customer-stall/customer-stall.js +++ b/static/components/customer-stall/customer-stall.js @@ -104,50 +104,53 @@ async function customerStall(path) { this.updateCart() }, addToCart(item) { - let prod = this.cart.products - if (prod.has(item.id)) { - let qty = prod.get(item.id).quantity - if (qty == item.quantity) { - this.$q.notify({ - type: 'warning', - message: `${item.name} only has ${item.quantity} units!`, - icon: 'production_quantity_limits' - }) - return - } - prod.set(item.id, { - ...prod.get(item.id), - quantity: qty + 1 - }) - } else { - prod.set(item.id, { - name: item.name, - quantity: 1, - price: item.price, - image: item?.images[0] || null - }) - } - this.$q.notify({ - type: 'positive', - message: `'${item.name}' added to cart`, - icon: 'thumb_up' - }) - this.cart.products = prod - this.updateCart() - }, - removeFromCart(item, del = false) { - let prod = this.cart.products - let qty = prod.get(item.id).quantity - if (qty == 1 || del) { - prod.delete(item.id) - } else { - prod.set(item.id, { - ...prod.get(item.id), - quantity: qty - 1 - }) - } - this.cart.products = prod - this.updateCart() + this.$emit('add-to-cart', item) + // console.log('### addToCart', item) + // console.log('### this.cart.products', this.cart.products) + // let prod = this.cart.products + // if (prod.has(item.id)) { + // let qty = prod.get(item.id).quantity + // if (qty == item.quantity) { + // this.$q.notify({ + // type: 'warning', + // message: `${item.name} only has ${item.quantity} units!`, + // icon: 'production_quantity_limits' + // }) + // return + // } + // prod.set(item.id, { + // ...prod.get(item.id), + // quantity: qty + 1 + // }) + // } else { + // prod.set(item.id, { + // name: item.name, + // quantity: 1, + // price: item.price, + // image: item?.images[0] || null + // }) + // } + // this.$q.notify({ + // type: 'positive', + // message: `'${item.name}' added to cart`, + // icon: 'thumb_up' + // }) + // this.cart.products = prod + // this.updateCart() + // }, + // removeFromCart(item, del = false) { + // let prod = this.cart.products + // let qty = prod.get(item.id).quantity + // if (qty == 1 || del) { + // prod.delete(item.id) + // } else { + // prod.set(item.id, { + // ...prod.get(item.id), + // quantity: qty - 1 + // }) + // } + // this.cart.products = prod + // this.updateCart() }, updateCart() { this.cart.total = 0 diff --git a/static/components/shopping-cart-list/shopping-cart-list.html b/static/components/shopping-cart-list/shopping-cart-list.html index 5ed595f..7cabd7f 100644 --- a/static/components/shopping-cart-list/shopping-cart-list.html +++ b/static/components/shopping-cart-list/shopping-cart-list.html @@ -1,3 +1,54 @@
- xxxx +
+ + + + + + + + + + + + + + + + + + By + + + + + + + + + + + + + +
+ {{product.name}} +
+
+
+ + + + + + 7:30PM + + + Proceed to Checkout + + +
+ +
+
\ No newline at end of file diff --git a/static/js/market.js b/static/js/market.js index 261c87c..50dba40 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -128,6 +128,7 @@ const market = async () => { }, async created() { this.merchants = this.$q.localStorage.getItem('nostrmarket.merchants') || [] + this.shoppingCarts = this.$q.localStorage.getItem('nostrmarket.shoppingCarts') || [] // Check for user stored this.account = this.$q.localStorage.getItem('diagonAlley.account') || null @@ -460,7 +461,7 @@ const market = async () => { } else { this.activeStall = null this.activeProduct = null - + url.searchParams.delete('merchant_pubkey') url.searchParams.delete('stall_id') url.searchParams.delete('product_id') @@ -542,7 +543,7 @@ const market = async () => { this.initNostr() }, - setActivePage(page = 'market'){ + setActivePage(page = 'market') { this.activePage = page }, @@ -563,7 +564,32 @@ const market = async () => { this.products = this.products.filter(p => p.pubkey !== publicKey) this.stalls = this.stalls.filter(p => p.pubkey !== publicKey) this.initNostr() // todo: improve + }, + + addProductToCart(item) { + console.log('### addProductToCart:', item) + + let stallCart = this.shoppingCarts.find(s => s.id === item.stall_id) + if (!stallCart) { + stallCart = { + id: item.stall_id, + products: [] + } + this.shoppingCarts.push(stallCart) + } + stallCart.merchant = this.merchants.find(m => m.publicKey === item.pubkey) + + const product = stallCart.products.find(p => p.id === item.id) + if (product) { + product.orderedQuantity = item.orderedQuantity || (product.orderedQuantity + 1) + } else { + stallCart.products.push({ ...item, orderedQuantity: 1 }) + } + + this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) + console.log('### this.shoppingCarts', this.shoppingCarts) } + } }) } diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index 5f4d6a2..102bb96 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -209,7 +209,7 @@ + @login-dialog="openAccountDialog" @change-page="navigateTo" @add-to-cart="addProductToCart">