Skip to content

Commit

Permalink
fix(storefront): Fetch products from list and get basic variations in…
Browse files Browse the repository at this point in the history
…fo on cart state update
  • Loading branch information
leomp12 committed Dec 17, 2024
1 parent 139cb0d commit 615237e
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions packages/storefront/src/lib/state/shopping-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 615237e

Please # to comment.