diff --git a/framework/shopify/types.ts b/framework/shopify/types.ts index 6ebfdf01d..9ad9fd016 100644 --- a/framework/shopify/types.ts +++ b/framework/shopify/types.ts @@ -12,7 +12,9 @@ export interface Cart extends Core.Cart { lineItems: LineItem[] } -export interface LineItem extends Core.LineItem {} +export interface LineItem extends Core.LineItem { + options: any[] +} /** * Cart mutations diff --git a/framework/shopify/utils/normalize.ts b/framework/shopify/utils/normalize.ts index 79074bf24..df8c7402b 100644 --- a/framework/shopify/utils/normalize.ts +++ b/framework/shopify/utils/normalize.ts @@ -40,8 +40,9 @@ const normalizeProductImages = ({ edges }: ImageConnection) => ...rest, })) -const normalizeProductVariants = ({ edges }: ProductVariantConnection) => - edges?.map(({ node: { id, selectedOptions } }) => ({ +const normalizeProductVariants = ({ edges }: ProductVariantConnection) => { + console.log(edges) + return edges?.map(({ node: { id, selectedOptions } }) => ({ id, options: selectedOptions.map(({ name, value }: SelectedOption) => normalizeProductOption({ @@ -51,6 +52,7 @@ const normalizeProductVariants = ({ edges }: ProductVariantConnection) => }) ), })) +} export function normalizeProduct(productNode: ShopifyProduct): any { const { @@ -66,7 +68,7 @@ export function normalizeProduct(productNode: ShopifyProduct): any { ...rest } = productNode - return { + const product = { id, name, vendor, @@ -79,6 +81,8 @@ export function normalizeProduct(productNode: ShopifyProduct): any { options: options ? options.map((o) => normalizeProductOption(o)) : [], ...rest, } + + return product } export function normalizeCart(checkout: Checkout): Cart { @@ -88,13 +92,13 @@ export function normalizeCart(checkout: Checkout): Cart { email: '', createdAt: checkout.createdAt, currency: { - code: checkout.currencyCode, + code: checkout.totalPriceV2?.currencyCode, }, taxesIncluded: checkout.taxesIncluded, lineItems: checkout.lineItems?.edges.map(normalizeLineItem), - lineItemsSubtotalPrice: checkout.subtotalPrice, - subtotalPrice: checkout.subtotalPrice, - totalPrice: checkout.totalPrice, + lineItemsSubtotalPrice: checkout.subtotalPriceV2?.amount, + subtotalPrice: checkout.subtotalPriceV2?.amount, + totalPrice: checkout.totalPriceV2?.amount, discounts: [], } } @@ -106,7 +110,7 @@ function normalizeLineItem({ id, variantId: String(variant?.id), productId: String(variant?.id), - name: `${title} - ${variant?.title}`, + name: `${title}`, quantity, variant: { id: String(variant?.id), @@ -116,10 +120,15 @@ function normalizeLineItem({ url: variant?.image?.originalSrc, }, requiresShipping: variant?.requiresShipping ?? false, - price: variant?.price, - listPrice: variant?.compareAtPrice, + price: variant?.priceV2?.amount, + listPrice: variant?.compareAtPriceV2?.amount, }, path: '', discounts: [], + options: [ + { + value: variant?.title, + }, + ], } } diff --git a/framework/shopify/utils/queries/get-checkout-query.ts b/framework/shopify/utils/queries/get-checkout-query.ts index f25542329..194e1619a 100644 --- a/framework/shopify/utils/queries/get-checkout-query.ts +++ b/framework/shopify/utils/queries/get-checkout-query.ts @@ -1,10 +1,18 @@ export const checkoutDetailsFragment = ` id webUrl - subtotalPrice - totalTax - totalPrice - currencyCode + subtotalPriceV2{ + amount + currencyCode + } + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } completedAt createdAt taxesIncluded @@ -27,7 +35,14 @@ export const checkoutDetailsFragment = ` width height } - price + priceV2{ + amount + currencyCode + } + compareAtPriceV2{ + amount + currencyCode + } } quantity } diff --git a/framework/shopify/utils/queries/get-product-query.ts b/framework/shopify/utils/queries/get-product-query.ts index d61824ed5..d054c023d 100644 --- a/framework/shopify/utils/queries/get-product-query.ts +++ b/framework/shopify/utils/queries/get-product-query.ts @@ -36,8 +36,14 @@ const getProductQuery = /* GraphQL */ ` name value } - price - compareAtPrice + priceV2 { + amount + currencyCode + } + compareAtPriceV2 { + amount + currencyCode + } } } } diff --git a/tsconfig.json b/tsconfig.json index 43dfd2a27..7aec4729c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,8 +22,8 @@ "@utils/*": ["utils/*"], "@commerce/*": ["framework/commerce/*"], "@commerce": ["framework/commerce"], - "@framework/*": ["framework/bigcommerce/*"], - "@framework": ["framework/bigcommerce"] + "@framework/*": ["framework/shopify/*"], + "@framework": ["framework/shopify"] } }, "include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],