diff --git a/src/compatibility/shopify-objects/content.ts b/src/compatibility/shopify-objects/content.ts new file mode 100644 index 0000000..728a5a1 --- /dev/null +++ b/src/compatibility/shopify-objects/content.ts @@ -0,0 +1,36 @@ +import { Drop } from 'liquidjs'; +import type { SwellRecord } from 'types/swell'; +import { StorefrontResource } from '@/resources'; + +/* + Combines product content and description + Use {{ product.content }} to render the description + Use {{ product.content.content_field }} to render the content field +*/ +export class ShopifySwellContent extends Drop { + public content: Record; + public description: string; + constructor(product?: StorefrontResource | SwellRecord) { + super(); + this.content = (product?.content as Record) || {}; + this.description = (product?.description as string) || ''; + } + + toString() { + return this.description; + } + + toObject() { + const combined = Object.assign({}, this.content); + + return combined; + } + + toJSON() { + return this.toObject(); + } + + toLiquid() { + return this.toObject(); + } +} diff --git a/src/compatibility/shopify-objects/product.ts b/src/compatibility/shopify-objects/product.ts index eee4a56..f6db319 100644 --- a/src/compatibility/shopify-objects/product.ts +++ b/src/compatibility/shopify-objects/product.ts @@ -28,6 +28,7 @@ import { isOptionAvailable, isGiftcard, } from '@/resources/product_helpers'; +import { ShopifySwellContent } from './content'; export default function ShopifyProduct( instance: ShopifyCompatibility, @@ -79,7 +80,7 @@ export default function ShopifyProduct( compare_at_price_max: compareAtPrice, compare_at_price_min: compareAtPrice, compare_at_price_varies: false, - content: defer(() => product.description), + content: defer(() => new ShopifySwellContent(product)), created_at: defer(() => product.date_created), description: defer(() => product.description), featured_image: deferWith(product, (product: SwellRecord) => { diff --git a/types/shopify.ts b/types/shopify.ts index effb531..77f1ddb 100644 --- a/types/shopify.ts +++ b/types/shopify.ts @@ -1,4 +1,5 @@ import { SHOPIFY_TO_SWELL_SORTING } from '@/compatibility/shopify-configs'; +import type { ShopifySwellContent } from '@/compatibility/shopify-objects/content'; import type { SwellData, ThemeSectionEnabledDisabled } from './swell'; @@ -523,7 +524,7 @@ export interface ShopifyProduct { compare_at_price_max: number; compare_at_price_min: number; compare_at_price_varies: boolean; - content: string; + content: ShopifySwellContent; created_at: string; description: string; featured_image?: ShopifyImage;