fix: update core charge appearance

Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
Chloe
2024-04-26 19:24:58 +07:00
parent 3a3ff3798f
commit 3bf7fa5af9
14 changed files with 196 additions and 146 deletions

View File

@@ -29,3 +29,6 @@ export const TAGS = {
export const HIDDEN_PRODUCT_TAG = 'nextjs-frontend-hidden';
export const DEFAULT_OPTION = 'Default Title';
export const SHOPIFY_GRAPHQL_API_ENDPOINT = '/api/2024-04/graphql.json';
export const CORE_WAIVER = 'core-waiver';
export const CORE_VARIANT_ID_KEY = 'coreVariantId';

View File

@@ -52,6 +52,9 @@ const productFragment = /* GraphQL */ `
waiverAvailable: metafield(namespace: "custom", key: "waiver_available") {
value
}
coreVariantId: metafield(namespace: "custom", key: "coreVariant") {
value
}
}
}
}

View File

@@ -183,8 +183,9 @@ const reshapeImages = (images: Connection<Image>, productTitle: string) => {
const reshapeVariants = (variants: ShopifyProductVariant[]): ProductVariant[] => {
return variants.map((variant) => ({
...variant,
coreCharge: parseMetaFieldValue<Money>(variant.coreCharge),
waiverAvailable: parseMetaFieldValue<boolean>(variant.waiverAvailable)
waiverAvailable: parseMetaFieldValue<boolean>(variant.waiverAvailable),
coreVariantId: variant.coreVariantId?.value || null,
coreCharge: parseMetaFieldValue<Money>(variant.coreCharge)
}));
};
@@ -404,6 +405,18 @@ export async function getProduct(handle: string): Promise<Product | undefined> {
return reshapeProduct(res.body.data.product, false);
}
export async function getProductVariant(handle: string): Promise<Product | undefined> {
const res = await shopifyFetch<ShopifyProductOperation>({
query: getProductQuery,
tags: [TAGS.products],
variables: {
handle
}
});
return reshapeProduct(res.body.data.product, false);
}
export async function getProductRecommendations(productId: string): Promise<Product[]> {
const res = await shopifyFetch<ShopifyProductRecommendationsOperation>({
query: getProductRecommendationsQuery,

View File

@@ -87,11 +87,16 @@ export type ProductVariant = {
waiverAvailable: boolean | null;
barcode: string | null;
sku: string | null;
coreVariantId: string | null;
};
export type ShopifyProductVariant = Omit<ProductVariant, 'coreCharge' | 'waiverAvailable'> & {
coreCharge: { value: string } | null;
export type ShopifyProductVariant = Omit<
ProductVariant,
'coreCharge' | 'waiverAvailable' | 'coreVariantId'
> & {
waiverAvailable: { value: string };
coreVariantId: { value: string } | null;
coreCharge: { value: string } | null;
};
export type SEO = {