The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
fix(storefront): avoid 4-level field expansion when retrieving cart (#1518)
Viktor Holike6f157e88280
diff --git a/apps/storefront/src/components/cells/CartItemsProducts/CartItemsProducts.tsx b/apps/storefront/src/components/cells/CartItemsProducts/CartItemsProducts.tsxindex 10277c89c..850965547 100644--- a/apps/storefront/src/components/cells/CartItemsProducts/CartItemsProducts.tsx+++ b/apps/storefront/src/components/cells/CartItemsProducts/CartItemsProducts.tsx@@ -23,7 +23,7 @@ export const CartItemsProducts = ({return (<div>{validProducts.map(product => {- const { options } = product.variant ?? {};+ const options = Object.entries(product.variant_option_values ?? {});const total = convertToLocale({amount: product.subtotal ?? 0,@@ -76,9 +76,9 @@ export const CartItemsProducts = ({</div><div className="lg:flex justify-between -mt-4 lg:mt-0"><div className="label-md text-secondary" data-testid="cart-item-details">- {options?.map(({ option, id, value }) => (- <p key={id}>- {option?.title}: <span className="text-primary">{value}</span>+ {options.map(([title, value]) => (+ <p key={title}>+ {title}: <span className="text-primary">{String(value)}</span></p>))}{change_quantity ? (diff --git a/apps/storefront/src/components/molecules/CartDropdownItem/CartDropdownItem.tsx b/apps/storefront/src/components/molecules/CartDropdownItem/CartDropdownItem.tsxindex 3ce587534..b8c95c917 100644--- a/apps/storefront/src/components/molecules/CartDropdownItem/CartDropdownItem.tsx+++ b/apps/storefront/src/components/molecules/CartDropdownItem/CartDropdownItem.tsx@@ -45,9 +45,9 @@ export const CartDropdownItem = ({<div className="py-2"><h4 className="heading-xs">{item.product_title}</h4><div className="label-md text-secondary">- {item.variant?.options?.map(({ option, id, value }, index) => (- <p key={id ?? index}>- {option?.title}: <span className="text-primary">{value}</span>+ {Object.entries(item.variant_option_values ?? {}).map(([title, value]) => (+ <p key={title}>+ {title}: <span className="text-primary">{String(value)}</span></p>))}<p>diff --git a/apps/storefront/src/lib/data/cart.ts b/apps/storefront/src/lib/data/cart.tsindex 8c3be6519..a1df0a418 100644--- a/apps/storefront/src/lib/data/cart.ts+++ b/apps/storefront/src/lib/data/cart.ts@@ -33,13 +33,16 @@ export async function retrieveCart(cartId?: string) {.query({$id: id,fields:- '*items,*region, *items.product, *items.variant, *items.variant.options, items.variant.options.option.title,' ++ '*items,*region, *items.product, *items.variant, *items.variant.options,' +'*items.thumbnail, *items.metadata, +items.total, *promotions, +shipping_methods.name, *items.offer, *items.offer.seller' +'',fetchOptions: { headers, cache: 'no-cache' }}).then(({ cart }) => cart)- .catch(() => null);+ .catch(error => {+ console.error('Failed to retrieve cart', error);+ return null;+ });}export async function getOrSetCart(countryCode: string) {