Skip to content

Commit

Permalink
Fix product properties for PDP
Browse files Browse the repository at this point in the history
  • Loading branch information
thalytafabrine committed Mar 13, 2024
1 parent 3e3bb98 commit a6b298e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/mock/documentTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
25 changes: 4 additions & 21 deletions src/__tests__/mock/searchProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -248,6 +227,7 @@ export const searchProductMock: SearchProduct & {
commertialOffer: {
AvailableQuantity: 15,
CacheVersionUsedToCallCheckout: '_',
GiftSkuIds: [],
Installments: [
{
InterestRate: 0,
Expand Down Expand Up @@ -944,6 +924,7 @@ export const searchProductMock: SearchProduct & {
spotPrice: 2180,
taxPercentage: 0,
teasers: [],
DeliverySlaSamples: [],
},
sellerDefault: true,
sellerId: '38900',
Expand All @@ -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: [],
Expand All @@ -966,6 +948,7 @@ export const searchProductMock: SearchProduct & {
spotPrice: 0,
taxPercentage: 0,
teasers: [],
DeliverySlaSamples: [],
},
sellerDefault: false,
sellerId: '1',
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/mock/vtexProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down
24 changes: 19 additions & 5 deletions src/convertSearchDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down Expand Up @@ -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: [],
}
}

Expand All @@ -266,7 +278,7 @@ const setDefaultSeller = (sellers: Array<Seller & { active: boolean }>): 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,
Expand Down Expand Up @@ -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,
Expand All @@ -422,8 +434,10 @@ export const convertSearchDocument = async (
ProductName,
BrandId,
BrandName,
NameComplement,
LinkId,
ProductRefId,
AlternateIds,
DirectCategoryId,
ProductTitle,
MetaTagDescription,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/typings/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,13 @@ declare global {
DeliverySlaSamplesPerRegion?: Record<string, { DeliverySlaPerTypes: any[]; Region: any | null }>
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
}>
Expand Down

0 comments on commit a6b298e

Please sign in to comment.