diff --git a/lnbits/extensions/diagonalley/templates/diagonalley/stall.html b/lnbits/extensions/diagonalley/templates/diagonalley/stall.html index a7a4ddca..5c585fd3 100644 --- a/lnbits/extensions/diagonalley/templates/diagonalley/stall.html +++ b/lnbits/extensions/diagonalley/templates/diagonalley/stall.html @@ -21,14 +21,56 @@ - + + {% raw %} + + {{ cart.size }} + + {% endraw %} + + + {% raw %} + + + {{p.quantity}} x + + + + + + + + + {{ p.name }} + + + + {{p.price}} sats + + + {% endraw %} + + +
+ +
+
+
@@ -54,7 +96,7 @@ right: 0; transform: translate(-50%, -50%); " - @click="sendAlert" + @click="addToCart(item)" > Add to cart @@ -121,17 +163,56 @@ return { products: [], searchText: null, - cart: [] + cart: { + total: 0, + size: 0, + products: new Map() + }, + cartMenu: [] + } + }, + computed: { + filterProducts() { + if (!this.searchText || this.searchText.length < 2) return this.products + return this.products.filter(p => { + return ( + p.product.includes(this.searchText) || + p.description.includes(this.searchText) || + p.categories.includes(this.searchText) + ) + }) } }, methods: { - sendAlert() { - alert('really') + addToCart(item) { + let prod = this.cart.products + if (prod.has(item.id)) { + let qty = prod.get(item.id).quantity + prod.set(item.id, { + ...prod.get(item.id), + quantity: qty + 1 + }) + } else { + prod.set(item.id, { + name: item.product, + quantity: 1, + price: item.price + }) + } + this.cart.total += item.price + this.cart.size++ + this.cart.products = prod + this.cartMenu = Array.from(prod, item => { + return {id: item[0], ...item[1]} + }) + console.log(this.cartMenu) } }, + placeOrder() { + return + }, created() { this.products = JSON.parse('{{ products | tojson }}') - console.log(this.searchText) } })