From 117caf32e23c1fcf0cd203877e16a05d1f966ca0 Mon Sep 17 00:00:00 2001 From: marzban-dev Date: Wed, 16 Apr 2025 23:27:38 +0330 Subject: [PATCH] Fix functionality --- .../global/product-detail/RemainQuantity.vue | 9 ++++--- .../global/product-detail/UpdateQuantity.vue | 24 ++++++++++++------- frontend/components/product/ProductHero.vue | 12 ++++------ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/frontend/components/global/product-detail/RemainQuantity.vue b/frontend/components/global/product-detail/RemainQuantity.vue index b47a72b..957e966 100644 --- a/frontend/components/global/product-detail/RemainQuantity.vue +++ b/frontend/components/global/product-detail/RemainQuantity.vue @@ -1,16 +1,15 @@ \ No newline at end of file + diff --git a/frontend/components/global/product-detail/UpdateQuantity.vue b/frontend/components/global/product-detail/UpdateQuantity.vue index 6b4102c..b399800 100644 --- a/frontend/components/global/product-detail/UpdateQuantity.vue +++ b/frontend/components/global/product-detail/UpdateQuantity.vue @@ -7,9 +7,7 @@ import type { ProductVariantProvideType } from "~/pages/product/[id].vue"; // provide / inject -const { selectedVariant } = inject( - "productVariant" -) as ProductVariantProvideType; +const { selectedVariant } = inject("productVariant") as ProductVariantProvideType; // state @@ -46,15 +44,14 @@ watch( ); watch(selectedVariant, (newValue) => { - quantity.value = newValue!.cart_quantity; + quantity.value = newValue!.cart_quantity === 0 ? 1 : newValue!.cart_quantity; }); // lifecycle onMounted(() => { - quantity.value = selectedVariant.value!.cart_quantity; + quantity.value = selectedVariant.value!.cart_quantity === 0 ? 1 : selectedVariant.value!.cart_quantity; }); - diff --git a/frontend/components/product/ProductHero.vue b/frontend/components/product/ProductHero.vue index 4322663..66b6fcf 100644 --- a/frontend/components/product/ProductHero.vue +++ b/frontend/components/product/ProductHero.vue @@ -37,13 +37,10 @@ const addItemToCart = async () => { // watch -watch( - () => selectedVariantId.value, - (newId) => { - const newVariant = product.value!.variants.find((variant) => variant.id === newId)!; - changeSelectedVariant(newVariant); - } -); +watch([selectedVariantId, product], ([selectedVariantId, product]) => { + const newVariant = product!.variants.find((variant) => variant.id === selectedVariantId)!; + changeSelectedVariant(newVariant); +}); watch( () => selectedColor.value, @@ -193,6 +190,7 @@ watch(