This commit is contained in:
Kristian Duda 2024-06-28 13:39:30 +02:00
parent 164833d96f
commit 4748088dea

View File

@ -7,7 +7,6 @@ import { ensureStartsWith } from 'lib/utils';
import { revalidateTag } from 'next/cache'; import { revalidateTag } from 'next/cache';
import { headers } from 'next/headers'; import { headers } from 'next/headers';
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { removeFromCartMutation } from './mutations/cart';
import { getPageQuery } from './queries/page'; import { getPageQuery } from './queries/page';
import { import {
CartItem, CartItem,
@ -21,8 +20,7 @@ import {
ProductOption, ProductOption,
ProductVariant, ProductVariant,
ShopifyCart, ShopifyCart,
ShopifyPageOperation, ShopifyPageOperation
ShopifyRemoveFromCartOperation
} from './types'; } from './types';
const domain = process.env.SHOPIFY_STORE_DOMAIN const domain = process.env.SHOPIFY_STORE_DOMAIN
@ -170,16 +168,10 @@ export async function addToCart(
} }
export async function removeFromCart(cartId: string, lineIds: string[]): Promise<ExCart> { export async function removeFromCart(cartId: string, lineIds: string[]): Promise<ExCart> {
const res = await shopifyFetch<ShopifyRemoveFromCartOperation>({ const prevCart = await findByID<Cart>('carts', cartId);
query: removeFromCartMutation, const lines = prevCart?.lines?.filter((lineItem) => !lineIds.includes(lineItem.id!)) ?? [];
variables: { const cart = await update<Cart>('carts', cartId, { lines });
cartId, return reshapeC(cart.doc);
lineIds
},
cache: 'no-store'
});
return reshapeCart(res.body.data.cartLinesRemove.cart);
} }
const mergeItems = async ( const mergeItems = async (