mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
feat: add vehicle details to cart attributes
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
@@ -19,7 +19,8 @@ import {
|
||||
addToCartMutation,
|
||||
createCartMutation,
|
||||
editCartItemsMutation,
|
||||
removeFromCartMutation
|
||||
removeFromCartMutation,
|
||||
setCartAttributesMutation
|
||||
} from './mutations/cart';
|
||||
import { getCartQuery } from './queries/cart';
|
||||
import {
|
||||
@@ -39,6 +40,7 @@ import {
|
||||
} from './queries/product';
|
||||
import {
|
||||
Cart,
|
||||
CartAttributeInput,
|
||||
CartItem,
|
||||
CartProductVariant,
|
||||
Collection,
|
||||
@@ -75,6 +77,7 @@ import {
|
||||
ShopifyProductVariant,
|
||||
ShopifyProductsOperation,
|
||||
ShopifyRemoveFromCartOperation,
|
||||
ShopifySetCartAttributesOperation,
|
||||
ShopifyUpdateCartOperation
|
||||
} from './types';
|
||||
|
||||
@@ -339,6 +342,19 @@ export async function addToCart(
|
||||
return reshapeCart(res.body.data.cartLinesAdd.cart);
|
||||
}
|
||||
|
||||
export async function setCartAttributes(cartId: string, attributes: CartAttributeInput[]) {
|
||||
const res = await shopifyFetch<ShopifySetCartAttributesOperation>({
|
||||
query: setCartAttributesMutation,
|
||||
variables: {
|
||||
attributes,
|
||||
cartId
|
||||
},
|
||||
cache: 'no-store'
|
||||
});
|
||||
|
||||
return res.body.data.cart;
|
||||
}
|
||||
|
||||
export async function removeFromCart(cartId: string, lineIds: string[]): Promise<Cart> {
|
||||
const res = await shopifyFetch<ShopifyRemoveFromCartOperation>({
|
||||
query: removeFromCartMutation,
|
||||
@@ -382,7 +398,6 @@ export async function getCart(cartId: string): Promise<Cart | undefined> {
|
||||
}
|
||||
|
||||
const cart = reshapeCart(res.body.data.cart);
|
||||
|
||||
let extendedCartLines = cart.lines;
|
||||
|
||||
const lineIdMap = {} as { [key: string]: string };
|
||||
|
@@ -11,6 +11,17 @@ export const addToCartMutation = /* GraphQL */ `
|
||||
${cartFragment}
|
||||
`;
|
||||
|
||||
export const setCartAttributesMutation = /* GraphQL */ `
|
||||
mutation setCartAttributes($attributes: [AttributeInput!]!, $cartId: ID!) {
|
||||
cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {
|
||||
cart {
|
||||
...cart
|
||||
}
|
||||
}
|
||||
}
|
||||
${cartFragment}
|
||||
`;
|
||||
|
||||
export const createCartMutation = /* GraphQL */ `
|
||||
mutation createCart($lineItems: [CartLineInput!]) {
|
||||
cartCreate(input: { lines: $lineItems }) {
|
||||
|
@@ -242,6 +242,16 @@ export type ShopifyAddToCartOperation = {
|
||||
};
|
||||
};
|
||||
|
||||
export type ShopifySetCartAttributesOperation = {
|
||||
data: {
|
||||
cart: ShopifyCart;
|
||||
};
|
||||
variables: {
|
||||
attributes: CartAttributeInput[];
|
||||
cartId: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type ShopifyRemoveFromCartOperation = {
|
||||
data: {
|
||||
cartLinesRemove: {
|
||||
@@ -428,3 +438,8 @@ export type Filter = {
|
||||
export const SCREEN_SIZES = ['small', 'medium', 'large', 'extra_large'] as const;
|
||||
|
||||
export type ScreenSize = (typeof SCREEN_SIZES)[number];
|
||||
|
||||
export type CartAttributeInput = {
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
|
Reference in New Issue
Block a user