Skip to content

Commit

Permalink
feat: added teasers to catalog loader (#185)
Browse files Browse the repository at this point in the history
* feat: added teasers to catalog loader

* fix: property minimumQuantity
  • Loading branch information
jonathanwlopes authored Aug 9, 2023
1 parent 7e97c1d commit af1d1c6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
23 changes: 22 additions & 1 deletion packs/vtex/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,27 @@ export interface Item {
}>;
}

export interface TeasersParameters {
"<Name>k__BackingField": string;
"<Value>k__BackingField": string;
}

export interface TeasersConditions {
"<MinimumQuantity>k__BackingField": number;
"<Parameters>k__BackingField": TeasersParameters[];
}

export interface TeasersEffect {
"<Parameters>k__BackingField": TeasersParameters[];
}

export interface Teasers {
"<Name>k__BackingField": string;
"<GeneralValues>k__BackingField": unknown;
"<Conditions>k__BackingField": TeasersConditions;
"<Effects>k__BackingField": TeasersEffect;
}

export interface CommertialOffer {
DeliverySlaSamplesPerRegion: Record<
string,
Expand All @@ -765,7 +786,7 @@ export interface CommertialOffer {
Installments: Installment[];
DiscountHighLight: unknown[];
GiftSkuIds: string[];
Teasers: Array<Record<string, unknown>>;
Teasers: Teasers[];
teasers?: Array<Record<string, unknown>>;
BuyTogether: unknown[];
ItemMetadataAttachment: unknown[];
Expand Down
35 changes: 34 additions & 1 deletion packs/vtex/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ export const toProduct = <P extends LegacyProductVTEX | ProductVTEX>(
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;

Expand Down Expand Up @@ -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["<Name>k__BackingField"],
generalValues: teaser["<GeneralValues>k__BackingField"],
conditions: {
minimumQuantity: teaser["<Conditions>k__BackingField"][
"<MinimumQuantity>k__BackingField"
],
parameters:
teaser["<Conditions>k__BackingField"]["<Parameters>k__BackingField"]
.map((parameter) => ({
name: parameter["<Name>k__BackingField"],
value: parameter["<Value>k__BackingField"],
})),
},
effects: {
parameters:
teaser["<Effects>k__BackingField"]["<Parameters>k__BackingField"].map(
(parameter) => ({
name: parameter["<Name>k__BackingField"],
value: parameter["<Value>k__BackingField"],
}),
),
},
})),
});

export const legacyFacetToFilter = (
name: string,
facets: LegacyFacet[],
Expand Down

0 comments on commit af1d1c6

Please sign in to comment.