Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/compatibility/shopify-objects/content.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>;
public description: string;
constructor(product?: StorefrontResource | SwellRecord) {
super();
this.content = (product?.content as Record<string, string>) || {};
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();
}
}
3 changes: 2 additions & 1 deletion src/compatibility/shopify-objects/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
isOptionAvailable,
isGiftcard,
} from '@/resources/product_helpers';
import { ShopifySwellContent } from './content';

export default function ShopifyProduct(
instance: ShopifyCompatibility,
Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion types/shopify.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand Down