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); setRemoving(true);
removeFromCart(cartId, item.id); await removeFromCart(cartId, item.id);
setRemoving(false); setRemoving(false);

View File

@ -30,12 +30,12 @@ export default function EditItemQuantityButton({
const method = type === 'minus' && item.quantity - 1 === 0 ? 'remove' : 'update'; const method = type === 'minus' && item.quantity - 1 === 0 ? 'remove' : 'update';
method === 'update' && method === 'update' &&
updateCart(cartId, { (await updateCart(cartId, {
lineItemId: item.id, lineItemId: item.id,
quantity: type === 'plus' ? item.quantity + 1 : item.quantity - 1 quantity: type === 'plus' ? item.quantity + 1 : item.quantity - 1
}); }));
method === 'remove' && removeFromCart(cartId, item.id); method === 'remove' && (await removeFromCart(cartId, item.id));
setEditing(false); setEditing(false);

View File

@ -38,14 +38,12 @@ export function AddToCart({
const isMutating = adding || isPending; const isMutating = adding || isPending;
async function handleAdd() { async function handleAdd() {
if (!availableForSale || !selectedVariantId) return; if (!availableForSale || !variants[0]) return;
setAdding(true); setAdding(true);
console.log({ cookie }); await addToCart(cookie.cartId, {
variantId: selectedVariantId || variants[0].id,
addToCart(cookie.cartId, {
variantId: selectedVariantId,
quantity: 1 quantity: 1
}); });

View File

@ -65,7 +65,7 @@ export default async function medusaRequest(
const reshapeCart = (cart: MedusaCart): Cart => { const reshapeCart = (cart: MedusaCart): Cart => {
const lines = cart?.items?.map((item) => reshapeLineItem(item)) || []; 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 checkoutUrl = '/';
const currencyCode = cart.region?.currency_code.toUpperCase() || 'USD'; const currencyCode = cart.region?.currency_code.toUpperCase() || 'USD';