From af1d1c614b0d0c6a7f0aaeddace8ab4efa993cfa Mon Sep 17 00:00:00 2001 From: Jonathan Lopes Date: Wed, 9 Aug 2023 15:35:21 -0300 Subject: [PATCH] feat: added teasers to catalog loader (#185) * feat: added teasers to catalog loader * fix: property minimumQuantity --- packs/vtex/types.ts | 23 ++++++++++++++++++++++- packs/vtex/utils/transform.ts | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/packs/vtex/types.ts b/packs/vtex/types.ts index d34957ea..31a8e5a9 100644 --- a/packs/vtex/types.ts +++ b/packs/vtex/types.ts @@ -757,6 +757,27 @@ export interface Item { }>; } +export interface TeasersParameters { + "k__BackingField": string; + "k__BackingField": string; +} + +export interface TeasersConditions { + "k__BackingField": number; + "k__BackingField": TeasersParameters[]; +} + +export interface TeasersEffect { + "k__BackingField": TeasersParameters[]; +} + +export interface Teasers { + "k__BackingField": string; + "k__BackingField": unknown; + "k__BackingField": TeasersConditions; + "k__BackingField": TeasersEffect; +} + export interface CommertialOffer { DeliverySlaSamplesPerRegion: Record< string, @@ -765,7 +786,7 @@ export interface CommertialOffer { Installments: Installment[]; DiscountHighLight: unknown[]; GiftSkuIds: string[]; - Teasers: Array>; + Teasers: Teasers[]; teasers?: Array>; BuyTogether: unknown[]; ItemMetadataAttachment: unknown[]; diff --git a/packs/vtex/utils/transform.ts b/packs/vtex/utils/transform.ts index 360040b1..3458a1a7 100644 --- a/packs/vtex/utils/transform.ts +++ b/packs/vtex/utils/transform.ts @@ -234,8 +234,11 @@ export const toProduct =

( const specificationsAdditionalProperty = isLegacySku(sku) ? toAdditionalPropertiesLegacy(sku) : toAdditionalProperties(sku); + const images = nonEmptyArray(sku.images) ?? [DEFAULT_IMAGE]; - const offers = (sku.sellers ?? []).map(toOffer).sort(bestOfferFirst); + const offers = (sku.sellers ?? []).map( + isLegacyProduct(product) ? toOfferLegacy : toOffer, + ).sort(bestOfferFirst); const highPriceIndex = getHighPriceIndex(offers); const lowPriceIndex = 0; @@ -439,6 +442,36 @@ const toOffer = ({ : "https://schema.org/OutOfStock", }); +const toOfferLegacy = ( + seller: SellerVTEX, +): Offer => ({ + ...toOffer(seller), + teasers: (seller.commertialOffer.Teasers ?? []).map((teaser) => ({ + name: teaser["k__BackingField"], + generalValues: teaser["k__BackingField"], + conditions: { + minimumQuantity: teaser["k__BackingField"][ + "k__BackingField" + ], + parameters: + teaser["k__BackingField"]["k__BackingField"] + .map((parameter) => ({ + name: parameter["k__BackingField"], + value: parameter["k__BackingField"], + })), + }, + effects: { + parameters: + teaser["k__BackingField"]["k__BackingField"].map( + (parameter) => ({ + name: parameter["k__BackingField"], + value: parameter["k__BackingField"], + }), + ), + }, + })), +}); + export const legacyFacetToFilter = ( name: string, facets: LegacyFacet[],