Skip to content

Commit

Permalink
performance of update cart
Browse files Browse the repository at this point in the history
  • Loading branch information
chanceaclark committed Oct 23, 2024
1 parent 2cf547d commit 73d8237
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ export async function updateItemQuantity({
variantEntityId,
selectedOptions,
}: UpdateProductQuantityParams) {
console.log('updateItemQuantity:start');

const customerId = await getSessionCustomerId();

try {
const cookieStore = await cookies();
const cartId = cookieStore.get('cartId')?.value;

console.log('updateItemQuantity:cookies');

if (!cartId) {
return { status: 'error', error: 'No cartId cookie found' };
}
Expand All @@ -51,6 +55,8 @@ export async function updateItemQuantity({
}

if (quantity === 0) {
console.log('updateItemQuantity:removeItem');

const result = await removeItem({ lineItemEntityId });

return result;
Expand All @@ -62,6 +68,8 @@ export async function updateItemQuantity({
selectedOptions && { selectedOptions },
);

console.log('updateItemQuantity:fetch:start');

const response = await client.fetch({
document: UpdateCartLineItemMutation,
variables: {
Expand All @@ -77,14 +85,22 @@ export async function updateItemQuantity({
fetchOptions: { cache: 'no-store' },
});

console.log('updateItemQuantity:fetch:end');

const cart = response.data.cart.updateCartLineItem?.cart;

console.log(cart);

if (!cart) {
return { status: 'error', error: 'Failed to change product quantity in Cart' };
}

console.log('updateItemQuantity:revalidatePath');

revalidatePath('/cart');

console.log('updateItemQuantity:end');

return { status: 'success', data: cart };
} catch (error: unknown) {
if (error instanceof Error) {
Expand Down
1 change: 0 additions & 1 deletion core/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ export default defineConfig({
use: { ...devices['Desktop Chrome'] },
},
],
retries: 5,
});

0 comments on commit 73d8237

Please sign in to comment.