From a6b298e4113034306ad29525335b95d2cee5f374 Mon Sep 17 00:00:00 2001 From: Thalyta Fabrine Date: Tue, 12 Mar 2024 11:20:37 +0100 Subject: [PATCH] Fix product properties for PDP --- CHANGELOG.md | 3 +++ src/__tests__/mock/documentTranslations.ts | 4 ++-- src/__tests__/mock/searchProduct.ts | 25 ++++------------------ src/__tests__/mock/vtexProduct.ts | 4 ++++ src/convertSearchDocument.ts | 24 ++++++++++++++++----- src/typings/global.ts | 4 ++-- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48d6e15..87488d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed +- Product `properties` and `metaTagDescription` for PDP compatibility. + ## [1.6.0] - 2024-03-05 ### Added diff --git a/src/__tests__/mock/documentTranslations.ts b/src/__tests__/mock/documentTranslations.ts index 173e297..81bb912 100644 --- a/src/__tests__/mock/documentTranslations.ts +++ b/src/__tests__/mock/documentTranslations.ts @@ -42,12 +42,12 @@ export const translationsMock: TranslatedProperty[] = [ { field: 'SpecificationName', context: '30', - translation: 'Variant_Color', + translation: 'Condição do Produto', }, { field: 'SpecificationValue', context: 'Roxo/Lilas', - translation: 'Purple', + translation: 'Novo', }, { field: 'SkuName', diff --git a/src/__tests__/mock/searchProduct.ts b/src/__tests__/mock/searchProduct.ts index e674e95..276d478 100644 --- a/src/__tests__/mock/searchProduct.ts +++ b/src/__tests__/mock/searchProduct.ts @@ -26,17 +26,6 @@ export const searchProductMock: SearchProduct & { }, }, specificationGroups: [ - { - name: 'Variantes', - originalName: 'Variantes', - specifications: [ - { - name: 'Variante_Cor', - originalName: 'Variante_Cor', - values: ['Roxo/Lilas'], - }, - ], - }, { name: 'Características do Produto', originalName: 'Características do Produto', @@ -68,11 +57,6 @@ export const searchProductMock: SearchProduct & { name: 'allSpecifications', originalName: 'allSpecifications', specifications: [ - { - name: 'Variante_Cor', - originalName: 'Variante_Cor', - values: ['Roxo/Lilas'], - }, { name: 'Condição do Produto', originalName: 'Condição do Produto', @@ -122,11 +106,6 @@ export const searchProductMock: SearchProduct & { }, ], properties: [ - { - name: 'Variante_Cor', - originalName: 'Variante_Cor', - values: ['Roxo/Lilas'], - }, { name: 'Condição do Produto', originalName: 'Condição do Produto', @@ -248,6 +227,7 @@ export const searchProductMock: SearchProduct & { commertialOffer: { AvailableQuantity: 15, CacheVersionUsedToCallCheckout: '_', + GiftSkuIds: [], Installments: [ { InterestRate: 0, @@ -944,6 +924,7 @@ export const searchProductMock: SearchProduct & { spotPrice: 2180, taxPercentage: 0, teasers: [], + DeliverySlaSamples: [], }, sellerDefault: true, sellerId: '38900', @@ -953,6 +934,7 @@ export const searchProductMock: SearchProduct & { addToCartLink: 'https://portal.vtexcommercestable.com.br/checkout/cart/add?sku=326782298&qty=1&seller=1&sc=1&price=0&cv=_&sc=1', commertialOffer: { + GiftSkuIds: [], AvailableQuantity: 0, CacheVersionUsedToCallCheckout: '_', Installments: [], @@ -966,6 +948,7 @@ export const searchProductMock: SearchProduct & { spotPrice: 0, taxPercentage: 0, teasers: [], + DeliverySlaSamples: [], }, sellerDefault: false, sellerId: '1', diff --git a/src/__tests__/mock/vtexProduct.ts b/src/__tests__/mock/vtexProduct.ts index c2db8f2..6f4ce02 100644 --- a/src/__tests__/mock/vtexProduct.ts +++ b/src/__tests__/mock/vtexProduct.ts @@ -152,6 +152,8 @@ export const vtexProductMock: SearchProduct = { 'https://portal.vtexcommercestable.com.br/checkout/cart/add?sku=3&qty=1&seller=1&sc=1&price=37577&cv=7BC1384A9AE1193BA0E88BF2E10E208A_&sc=1', sellerDefault: true, commertialOffer: { + DeliverySlaSamples: [], + GiftSkuIds: [], discountHighlights: [], teasers: [ { @@ -417,6 +419,8 @@ export const vtexProductMock: SearchProduct = { 'https://portal.vtexcommercestable.com.br/checkout/cart/add?sku=4&qty=1&seller=1&sc=1&price=60030&cv=7BC1384A9AE1193BA0E88BF2E10E208A_&sc=1', sellerDefault: true, commertialOffer: { + DeliverySlaSamples: [], + GiftSkuIds: [], discountHighlights: [], teasers: [ { diff --git a/src/convertSearchDocument.ts b/src/convertSearchDocument.ts index aa57b01..7d2266f 100644 --- a/src/convertSearchDocument.ts +++ b/src/convertSearchDocument.ts @@ -93,6 +93,7 @@ const specificationsInfoFromDocument = ( }) groupSpecs + .filter((specification) => !specification.Field.IsStockKeppingUnit) .map((specification) => ({ name: getTranslationInfo('SpecificationName', translations, specification.FieldId) ?? specification.Name, originalName: specification.Name, @@ -102,7 +103,7 @@ const specificationsInfoFromDocument = ( })) .forEach((spec) => properties.push(spec)) - const visibleSpecs = groupSpecs.filter((spec) => spec.IsOnProductDetails) + const visibleSpecs = groupSpecs.filter((spec) => spec.IsOnProductDetails && !spec.Field.IsStockKeppingUnit) if (visibleSpecs.length) { specificationGroups.push({ @@ -248,6 +249,17 @@ const buildCommercialOffer = (skuDocumentOffer: SalesChannelOffer, unitMultiplie AvailableQuantity: skuDocumentOffer.AvailableQuantity, teasers: skuDocumentOffer.RatesAndBenefitsData ? buildTeasers(skuDocumentOffer.RatesAndBenefitsData) : [], Installments: buildInstallments(skuDocumentOffer.PaymentOptions, unitMultiplier), + GiftSkuIds: [], + BuyTogether: [], + DeliverySlaSamples: skuDocumentOffer.AvailableQuantity + ? [ + { + DeliverySlaPerTypes: [], + Region: null, + }, + ] + : [], + ItemMetadataAttachment: [], } } @@ -266,7 +278,7 @@ const setDefaultSeller = (sellers: Array): Seller[ const sellersWithDefault = sellers.map((seller) => { return { sellerId: seller.sellerId, - sellerDefault: seller.sellerId === defaultSeller.sellerId, + sellerDefault: defaultSeller ? seller.sellerId === defaultSeller.sellerId : seller.sellerId === '1', sellerName: seller.sellerName, addToCartLink: seller.addToCartLink, commertialOffer: seller.commertialOffer, @@ -396,7 +408,7 @@ export const itemsFromSearchDocuments = ( unitMultiplier: skuDocument.UnitMultiplier, modalType: skuDocument.ModalType, images, - videos: skuDocument.Videos, + Videos: skuDocument.Videos, variations, sellers: getSkuSellers(offer, skuDocument.UnitMultiplier), attachments, @@ -422,8 +434,10 @@ export const convertSearchDocument = async ( ProductName, BrandId, BrandName, + NameComplement, LinkId, ProductRefId, + AlternateIds, DirectCategoryId, ProductTitle, MetaTagDescription, @@ -458,7 +472,7 @@ export const convertSearchDocument = async ( productId: ProductId, productName: getTranslationInfo('ProductName', translations) ?? ProductName, cacheId: `sp-${ProductId}`, - productReference: ProductRefId, + productReference: ProductRefId || AlternateIds.RefId, linkText: LinkId, brand: getTranslationInfo('BrandName', translations) ?? BrandName, brandId: BrandId, @@ -468,7 +482,7 @@ export const convertSearchDocument = async ( priceRange: getPriceRange(items), categoryId: DirectCategoryId.toString(), productTitle: ProductTitle, - metaTagDescription: MetaTagDescription ?? '', + metaTagDescription: MetaTagDescription ?? NameComplement ?? '', clusterHighlights: objToNameValue('id', 'name', ProductClusterHighlights), productClusters: objToNameValue('id', 'name', ProductClusterNames), searchableClusters, diff --git a/src/typings/global.ts b/src/typings/global.ts index 2dd68a9..661e15a 100644 --- a/src/typings/global.ts +++ b/src/typings/global.ts @@ -669,13 +669,13 @@ declare global { DeliverySlaSamplesPerRegion?: Record Installments: SearchInstallment[] discountHighlights?: any[] - GiftSkuIds?: string[] + GiftSkuIds: string[] teasers: Teaser[] BuyTogether?: any[] ItemMetadataAttachment?: any[] spotPrice: number taxPercentage: number - DeliverySlaSamples?: Array<{ + DeliverySlaSamples: Array<{ DeliverySlaPerTypes: any[] Region: any | null }>