From 761a3137a6c984ea24a07ad521757b3a48cab9e6 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 7 Jul 2023 14:24:00 +0300 Subject: [PATCH] feat: stuff --- .../market-config/market-config.html | 2 +- .../components/product-card/product-card.html | 2 +- .../product-detail/product-detail.html | 1 + .../shopping-cart-checkout.html | 125 ++++++++++++++++++ .../shopping-cart-checkout.js | 46 +++++++ .../shopping-cart-list.html | 26 ++-- .../shopping-cart-list/shopping-cart-list.js | 6 + static/js/market.js | 12 +- templates/nostrmarket/market.html | 22 +-- 9 files changed, 221 insertions(+), 21 deletions(-) create mode 100644 static/components/shopping-cart-checkout/shopping-cart-checkout.html create mode 100644 static/components/shopping-cart-checkout/shopping-cart-checkout.js diff --git a/static/components/market-config/market-config.html b/static/components/market-config/market-config.html index 3ac87fc..63695d2 100644 --- a/static/components/market-config/market-config.html +++ b/static/components/market-config/market-config.html @@ -33,7 +33,7 @@ {{ publicKey }} - + diff --git a/static/components/product-card/product-card.html b/static/components/product-card/product-card.html index c7ab5bf..fcff78e 100644 --- a/static/components/product-card/product-card.html +++ b/static/components/product-card/product-card.html @@ -4,7 +4,7 @@ alt="Product Image" loading="lazy" spinner-color="white" fit="contain" height="300px"> - + + + + + + + + + + + + + + + + + By + + + + + + + + + + + +
+
+ Subtotal: +
+
+ +
+
+ {{formatCurrency(cartTotal, + cart.products[0]?.currency)}} +
+
+
+
+ Shipping: +
+
+ +
+
+ 00.00 +
+
+ +
+
+ Total: +
+
+ +
+
+ 00.00 +
+
+ + + +
+ + + + + Payment Method + + +
+ + + + + + Request Invoice + + +
+ + + \ No newline at end of file diff --git a/static/components/shopping-cart-checkout/shopping-cart-checkout.js b/static/components/shopping-cart-checkout/shopping-cart-checkout.js new file mode 100644 index 0000000..8a52b9a --- /dev/null +++ b/static/components/shopping-cart-checkout/shopping-cart-checkout.js @@ -0,0 +1,46 @@ +async function shoppingCartCheckout(path) { + const template = await loadTemplateAsync(path) + + Vue.component('shopping-cart-checkout', { + name: 'shopping-cart-checkout', + template, + + props: ['cart'], + data: function () { + return { + paymentMethod: 'ln', + paymentOptions: [ + { + label: 'Lightning Network', + value: 'ln' + }, + { + label: 'BTC Onchain', + value: 'btc' + }, + { + label: 'Cashu', + value: 'cashu' + } + ] + } + }, + computed: { + cartTotal() { + if (!this.cart.products?.length) return 0 + return this.cart.products.reduce((t, p) => p.price + t, 0) + }, + }, + methods: { + formatCurrency: function (value, unit) { + return formatCurrency(value, unit) + }, + requestInvoice: function () { + + } + }, + created() { + console.log('### shoppingCartCheckout', this.cart) + } + }) +} diff --git a/static/components/shopping-cart-list/shopping-cart-list.html b/static/components/shopping-cart-list/shopping-cart-list.html index 5073af9..8a5cfe3 100644 --- a/static/components/shopping-cart-list/shopping-cart-list.html +++ b/static/components/shopping-cart-list/shopping-cart-list.html @@ -1,4 +1,9 @@
+ + + No products in cart! + +
@@ -21,7 +26,11 @@ - +
+ + Clear Cart + +
@@ -51,20 +60,19 @@ {{ formatCurrency(product.price, product.currency)}} - + - + - + {{ formatCurrency(product.price * product.orderedQuantity, product.currency)}}
- +
@@ -75,9 +83,11 @@ + + Total: {{cartTotalFormatted(cart)}} - + Proceed to Checkout diff --git a/static/components/shopping-cart-list/shopping-cart-list.js b/static/components/shopping-cart-list/shopping-cart-list.js index 737189e..570bd05 100644 --- a/static/components/shopping-cart-list/shopping-cart-list.js +++ b/static/components/shopping-cart-list/shopping-cart-list.js @@ -22,8 +22,14 @@ async function shoppingCartList(path) { removeProduct: function (stallId, productId) { this.$emit('remove-from-cart', { stallId, productId }) }, + removeCart: function (stallId) { + this.$emit('remove-cart', stallId) + }, quantityChanged: function (product) { this.$emit('add-to-cart', product) + }, + proceedToCheckout: function(cart){ + this.$emit('checkout-cart', cart) } }, created() { } diff --git a/static/js/market.js b/static/js/market.js index c220a7b..da0a2e8 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -31,6 +31,7 @@ const market = async () => { productDetail('static/components/product-detail/product-detail.html'), shoppingCart('static/components/shopping-cart/shopping-cart.html'), shoppingCartList('static/components/shopping-cart-list/shopping-cart-list.html'), + shoppingCartCheckout('static/components/shopping-cart-checkout/shopping-cart-checkout.html'), chatDialog('static/components/chat-dialog/chat-dialog.html'), marketConfig('static/components/market-config/market-config.html') ]) @@ -52,6 +53,7 @@ const market = async () => { merchants: [], shoppingCarts: [], + shoppingCartCheckout: null, activePage: 'market', @@ -592,7 +594,6 @@ const market = async () => { product.orderedQuantity = Math.min(product.quantity, item.orderedQuantity || (product.orderedQuantity + 1)) this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) - console.log('### this.shoppingCarts', this.shoppingCarts) }, removeProductFromCart(item) { @@ -604,6 +605,15 @@ const market = async () => { } this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) } + }, + removeCart(stallId) { + this.shoppingCarts = this.shoppingCarts.filter(s => s.id !== stallId) + this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) + }, + + checkoutCart(cart) { + this.shoppingCartCheckout = cart + this.setActivePage('shopping-cart-checkout') } } diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index aa109e7..d188193 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -181,11 +181,11 @@ User Config - Shopping Cart - - + + @@ -211,7 +211,10 @@ + @add-to-cart="addProductToCart" @remove-from-cart="removeProductFromCart" @remove-cart="removeCart" + @checkout-cart="checkoutCart"> + - +
Account Setup
@@ -236,16 +239,13 @@ + :error="accountDialog.data.key && !isValidAccountKey" hint="Enter you private key"> - Close + Close
@@ -292,6 +292,8 @@ +