From fa4eff52e4a959549a4add8c1eed6d4636d73f8f Mon Sep 17 00:00:00 2001 From: SergeySwell Date: Thu, 27 Nov 2025 12:39:39 +0100 Subject: [PATCH 1/2] support product content fields --- src/compatibility/shopify-objects/content.ts | 40 ++++++++++++++++++++ src/compatibility/shopify-objects/product.ts | 3 +- types/shopify.ts | 3 +- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/compatibility/shopify-objects/content.ts diff --git a/src/compatibility/shopify-objects/content.ts b/src/compatibility/shopify-objects/content.ts new file mode 100644 index 0000000..d9953a1 --- /dev/null +++ b/src/compatibility/shopify-objects/content.ts @@ -0,0 +1,40 @@ +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( + {}, + { description: this.description }, + 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; From 357eb443aab9a5407c1c684cccdb01bc8be83957 Mon Sep 17 00:00:00 2001 From: SergeySwell Date: Thu, 27 Nov 2025 17:57:53 +0100 Subject: [PATCH 2/2] do not add description to object --- src/compatibility/shopify-objects/content.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/compatibility/shopify-objects/content.ts b/src/compatibility/shopify-objects/content.ts index d9953a1..728a5a1 100644 --- a/src/compatibility/shopify-objects/content.ts +++ b/src/compatibility/shopify-objects/content.ts @@ -21,11 +21,7 @@ export class ShopifySwellContent extends Drop { } toObject() { - const combined = Object.assign( - {}, - { description: this.description }, - this.content, - ); + const combined = Object.assign({}, this.content); return combined; }