diff --git a/components/cart/delete-item-button.tsx b/components/cart/delete-item-button.tsx index 5aa312454..2f5bc70db 100644 --- a/components/cart/delete-item-button.tsx +++ b/components/cart/delete-item-button.tsx @@ -20,7 +20,7 @@ export default function DeleteItemButton({ item }: { item: CartItem }) { setRemoving(true); - removeFromCart(cartId, item.id); + await removeFromCart(cartId, item.id); setRemoving(false); diff --git a/components/cart/edit-item-quantity-button.tsx b/components/cart/edit-item-quantity-button.tsx index a8ec9f35f..f252f0e3f 100644 --- a/components/cart/edit-item-quantity-button.tsx +++ b/components/cart/edit-item-quantity-button.tsx @@ -30,12 +30,12 @@ export default function EditItemQuantityButton({ const method = type === 'minus' && item.quantity - 1 === 0 ? 'remove' : 'update'; method === 'update' && - updateCart(cartId, { + (await updateCart(cartId, { lineItemId: item.id, quantity: type === 'plus' ? item.quantity + 1 : item.quantity - 1 - }); + })); - method === 'remove' && removeFromCart(cartId, item.id); + method === 'remove' && (await removeFromCart(cartId, item.id)); setEditing(false); diff --git a/components/product/add-to-cart.tsx b/components/product/add-to-cart.tsx index 37e00f623..4709900ac 100644 --- a/components/product/add-to-cart.tsx +++ b/components/product/add-to-cart.tsx @@ -38,14 +38,12 @@ export function AddToCart({ const isMutating = adding || isPending; async function handleAdd() { - if (!availableForSale || !selectedVariantId) return; + if (!availableForSale || !variants[0]) return; setAdding(true); - console.log({ cookie }); - - addToCart(cookie.cartId, { - variantId: selectedVariantId, + await addToCart(cookie.cartId, { + variantId: selectedVariantId || variants[0].id, quantity: 1 }); diff --git a/lib/medusa/index.ts b/lib/medusa/index.ts index a093ebe1f..cd994ce7d 100644 --- a/lib/medusa/index.ts +++ b/lib/medusa/index.ts @@ -65,7 +65,7 @@ export default async function medusaRequest( const reshapeCart = (cart: MedusaCart): Cart => { const lines = cart?.items?.map((item) => reshapeLineItem(item)) || []; - const totalQuantity = lines.length; + const totalQuantity = lines.reduce((a, b) => a + b.quantity, 0); const checkoutUrl = '/'; const currencyCode = cart.region?.currency_code.toUpperCase() || 'USD';