mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 22:16:58 +00:00
fix: cart bugs
This commit is contained in:
parent
834e6bdff3
commit
f739c891b0
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user