From 0b715c2dd240652c9bcff2953e1c06b8bc8ae74a Mon Sep 17 00:00:00 2001 From: cond0r Date: Thu, 15 Apr 2021 18:35:31 +0300 Subject: [PATCH] Add product description html (#274) --- components/product/ProductView/ProductView.tsx | 2 +- framework/commerce/types.ts | 1 + framework/shopify/product/get-product.ts | 5 ++--- framework/shopify/utils/normalize.ts | 4 +++- framework/shopify/utils/queries/get-all-products-query.ts | 1 - 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx index 05e7a1cee..3b09fa39a 100644 --- a/components/product/ProductView/ProductView.tsx +++ b/components/product/ProductView/ProductView.tsx @@ -136,7 +136,7 @@ const ProductView: FC = ({ product }) => { ))}
- +
diff --git a/framework/commerce/types.ts b/framework/commerce/types.ts index a398070ac..86361fd9f 100644 --- a/framework/commerce/types.ts +++ b/framework/commerce/types.ts @@ -163,6 +163,7 @@ interface Entity { export interface Product extends Entity { name: string description: string + descriptionHtml?: string slug?: string path?: string images: ProductImage[] diff --git a/framework/shopify/product/get-product.ts b/framework/shopify/product/get-product.ts index 1f00288c7..1d861e1a1 100644 --- a/framework/shopify/product/get-product.ts +++ b/framework/shopify/product/get-product.ts @@ -21,11 +21,10 @@ const getProduct = async (options: { const { data }: GraphQLFetcherResult = await config.fetch(getProductQuery, { variables, }) - - const { productByHandle: product } = data + const { productByHandle } = data return { - product: product ? normalizeProduct(product) : null, + product: productByHandle ? normalizeProduct(productByHandle) : null, } } diff --git a/framework/shopify/utils/normalize.ts b/framework/shopify/utils/normalize.ts index 25bdca053..4ebc3a1ae 100644 --- a/framework/shopify/utils/normalize.ts +++ b/framework/shopify/utils/normalize.ts @@ -83,6 +83,7 @@ export function normalizeProduct(productNode: ShopifyProduct): Product { images, variants, description, + descriptionHtml, handle, priceRange, options, @@ -93,7 +94,6 @@ export function normalizeProduct(productNode: ShopifyProduct): Product { id, name, vendor, - description, path: `/${handle}`, slug: handle?.replace(/^\/+|\/+$/g, ''), price: money(priceRange?.minVariantPrice), @@ -104,6 +104,8 @@ export function normalizeProduct(productNode: ShopifyProduct): Product { .filter((o) => o.name !== 'Title') // By default Shopify adds a 'Title' name when there's only one option. We don't need it. https://community.shopify.com/c/Shopify-APIs-SDKs/Adding-new-product-variant-is-automatically-adding-quot-Default/td-p/358095 .map((o) => normalizeProductOption(o)) : [], + ...(description && { description }), + ...(descriptionHtml && { descriptionHtml }), ...rest, } diff --git a/framework/shopify/utils/queries/get-all-products-query.ts b/framework/shopify/utils/queries/get-all-products-query.ts index 5eb44c7a7..f48140d31 100644 --- a/framework/shopify/utils/queries/get-all-products-query.ts +++ b/framework/shopify/utils/queries/get-all-products-query.ts @@ -9,7 +9,6 @@ edges { title vendor handle - description priceRange { minVariantPrice { amount