From 615237e2fc78e47cc48f8595b65c960ddfa9e58a Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Tue, 17 Dec 2024 18:18:52 -0300 Subject: [PATCH] fix(storefront): Fetch products from list and get basic variations info on cart state update --- .../storefront/src/lib/state/shopping-cart.ts | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/storefront/src/lib/state/shopping-cart.ts b/packages/storefront/src/lib/state/shopping-cart.ts index cd1f723f2..08bd4b1b2 100644 --- a/packages/storefront/src/lib/state/shopping-cart.ts +++ b/packages/storefront/src/lib/state/shopping-cart.ts @@ -57,16 +57,35 @@ const updateCartState = async () => { return; } try { - const { data } = await api.get('search/v1', { + const { data } = await api.get('products', { params: { _id: productIds }, + fields: [ + "sku", + "name", + "slug", + "available", + "visible", + "price", + "base_price", + "quantity", + "min_quantity", + "inventory", + "kit_composition", + "pictures.normal", + "variations.sku", + "variations.name", + "variations.production_time", + "variations.base_price", + "variations.picture_id", + ] as const, }); const storedItems = [...shoppingCart.items]; resetCartItems(); - data.result.forEach((searchItem) => { - const storedItem = storedItems.find((item) => item.product_id === searchItem._id); + data.result.forEach((productItem) => { + const storedItem = storedItems.find((item) => item.product_id === productItem._id); if (!storedItem) return; const { variation_id: variationId, quantity } = storedItem; - const cartItem = addProductToCart(searchItem, variationId, quantity); + const cartItem = addProductToCart(productItem, variationId, quantity); if (!cartItem) return; if (storedItem._id) { cartItem._id = storedItem._id;