From d9569c50ed3434973d5777fc1ede4a5374d95e37 Mon Sep 17 00:00:00 2001 From: Beniamin Sinca Date: Fri, 10 Feb 2023 12:20:41 +0000 Subject: [PATCH 1/2] fix(useCart): canAddToCart not working correctly Importing the correct status types then comparing with the product stock status. --- modules/checkout/composables/useCart/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/checkout/composables/useCart/index.ts b/modules/checkout/composables/useCart/index.ts index 624baa8..42a093d 100644 --- a/modules/checkout/composables/useCart/index.ts +++ b/modules/checkout/composables/useCart/index.ts @@ -9,7 +9,7 @@ import { removeCouponCommand } from '~/modules/checkout/composables/useCart/comm import { removeItemCommand } from '~/modules/checkout/composables/useCart/commands/removeItemCommand'; import { updateItemQtyCommand } from '~/modules/checkout/composables/useCart/commands/updateItemQtyCommand'; import { Logger } from '~/helpers/logger'; -import { Cart, CartItemInterface, ProductInterface } from '~/modules/GraphQL/types'; +import { Cart, CartItemInterface, ProductInterface, ProductStockStatus } from '~/modules/GraphQL/types'; import { useCartStore } from '~/modules/checkout/stores/cart'; import { useWishlist } from '~/modules/wishlist/composables/useWishlist'; import { Product } from '~/modules/catalog/product/types'; @@ -272,7 +272,7 @@ PRODUCT return !!product?.configurable_product_options_selection?.variant ?.uid; } - const inStock = product?.stock_status || ''; + const inStock = product.stock_status === ProductStockStatus.InStock ? true : false; const stockLeft = product?.only_x_left_in_stock === null ? true : qty <= product?.only_x_left_in_stock; From db7039d60a7a56cf06efcc744c8f5efae6cc193d Mon Sep 17 00:00:00 2001 From: Beniamin Sinca Date: Fri, 10 Feb 2023 15:24:02 +0000 Subject: [PATCH 2/2] Update modules/checkout/composables/useCart/index.ts Co-authored-by: Bartosz Herba --- modules/checkout/composables/useCart/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/checkout/composables/useCart/index.ts b/modules/checkout/composables/useCart/index.ts index 42a093d..5885bd1 100644 --- a/modules/checkout/composables/useCart/index.ts +++ b/modules/checkout/composables/useCart/index.ts @@ -272,7 +272,7 @@ PRODUCT return !!product?.configurable_product_options_selection?.variant ?.uid; } - const inStock = product.stock_status === ProductStockStatus.InStock ? true : false; + const inStock = product?.stock_status === ProductStockStatus.InStock ? true : false; const stockLeft = product?.only_x_left_in_stock === null ? true : qty <= product?.only_x_left_in_stock;