Skip to content

Commit

Permalink
[Shopify] - Add more information to product collections (#332)
Browse files Browse the repository at this point in the history
* feat: add more information to product collections

* refactor: avoid break changes & add more informations

* style: remove unused type

---------

Co-authored-by: guitavano <[email protected]>
  • Loading branch information
vitoUwu and guitavano authored Jan 31, 2024
1 parent 943f138 commit 4060f21
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions shopify/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
ProductFragment as ProductShopify,
ProductVariantFragment as SkuShopify,
} from "./storefront/storefront.graphql.gen.ts";
import { SelectedOption as SelectedOptionShopify } from "./types.ts";

const getPath = ({ handle }: ProductShopify, sku?: SkuShopify) =>
sku
Expand Down Expand Up @@ -151,8 +150,26 @@ export const toProduct = (
...product.tags?.map((value) =>
toPropertyValue({ name: "TAG", value })
),
...product.collections?.nodes.map(({ title }) =>
toPropertyValue({ name: "COLLECTION", value: title })
...product.collections?.nodes.map((
{ title, handle, id, description, descriptionHtml, image },
) =>
toPropertyValue({
"@id": id,
name: "COLLECTION",
value: title,
valueReference: handle,
description,
disambiguatingDescription: descriptionHtml,
...(image &&
{
image: [{
"@type": "ImageObject",
encodingFormat: "image",
alternateName: image.altText ?? "",
url: image.url,
}],
}),
})
),
],
image: nonEmptyArray(images.nodes)?.map((img) => ({
Expand Down Expand Up @@ -189,7 +206,9 @@ export const toProduct = (
};
};

const toPropertyValue = (option: SelectedOptionShopify): PropertyValue => ({
const toPropertyValue = (
option: Omit<PropertyValue, "@type">,
): PropertyValue => ({
"@type": "PropertyValue",
...option,
});
Expand Down

0 comments on commit 4060f21

Please sign in to comment.