mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 12:47:50 +00:00
cart
This commit is contained in:
parent
164833d96f
commit
4748088dea
@ -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 (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user