fix: cart bugs

This commit is contained in:
Victor Gerbrands 2023-05-09 19:16:13 +02:00
parent 834e6bdff3
commit f739c891b0
4 changed files with 8 additions and 10 deletions

View File

@ -20,7 +20,7 @@ export default function DeleteItemButton({ item }: { item: CartItem }) {
setRemoving(true);
removeFromCart(cartId, item.id);
await removeFromCart(cartId, item.id);
setRemoving(false);

View File

@ -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);

View File

@ -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
});

View File

@ -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';