From 7fa0724246b552d04c929a989b26d3b252eae772 Mon Sep 17 00:00:00 2001 From: Marcos Maia Date: Fri, 25 Oct 2024 12:13:51 -0300 Subject: [PATCH 1/6] fix isabela-dias --- wap/loaders/productDetailsPage.ts | 2 ++ wap/utils/transform.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/wap/loaders/productDetailsPage.ts b/wap/loaders/productDetailsPage.ts index f27beb603..79404797f 100644 --- a/wap/loaders/productDetailsPage.ts +++ b/wap/loaders/productDetailsPage.ts @@ -32,6 +32,8 @@ const loader = async ( const itemListElement = toBreadcrumbList(data.estrutura.breadcrumb, baseUrl); + Deno.writeTextFileSync(`product_uappi.json`, JSON.stringify(data.conteudo)) + const product = toProduct(data.conteudo, baseUrl); return { diff --git a/wap/utils/transform.ts b/wap/utils/transform.ts index c00041037..418ce031b 100644 --- a/wap/utils/transform.ts +++ b/wap/utils/transform.ts @@ -188,6 +188,18 @@ export const toProduct = ( }); }); + product?.caracteristicas?.forEach((item) => { + item.itens.forEach((carac) => { + additionalProperty.push({ + "@type": "PropertyValue", + name: carac.label, + value: carac.valor, + valueReference: item.nome, + }); + + }) + }); + if (product?.filtros) { product?.filtros.forEach((filtro) => { additionalProperty.push({ From bb177c943e01441e701a75bf860a59fbe2eb3887 Mon Sep 17 00:00:00 2001 From: Marcos Maia Date: Tue, 29 Oct 2024 13:26:39 -0300 Subject: [PATCH 2/6] fix brand --- wap/utils/transform.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wap/utils/transform.ts b/wap/utils/transform.ts index 418ce031b..adb20295d 100644 --- a/wap/utils/transform.ts +++ b/wap/utils/transform.ts @@ -284,7 +284,7 @@ export const toProduct = ( const isVariantOf: ProductGroup = { "@type": "ProductGroup", hasVariant, - productGroupID: product.id.toString(), + productGroupID: product?.id?.toString(), additionalProperty, }; @@ -295,10 +295,10 @@ export const toProduct = ( description: product.descricoes.longa, brand: { "@type": "Brand", - identifier: product.marca.id.toString(), - name: product.marca.nome, - logo: product.marca.imagem, - url: new URL(product.marca.rota.path, baseUrl).href, + identifier: product.marca?.id?.toString(), + name: product.marca?.nome, + logo: product.marca?.imagem, + url: new URL(product.marca?.rota?.path, baseUrl).href, }, url: `${getUrl(`/${product.rota.params.produto}`, baseUrl).href}.html`, image: images.length ? images : [DEFAULT_IMAGE], From 3721e3f84780484d4d2dea6f493a1371202f0346 Mon Sep 17 00:00:00 2001 From: Marcos Maia Date: Tue, 29 Oct 2024 13:30:44 -0300 Subject: [PATCH 3/6] removing deno write --- wap/loaders/productDetailsPage.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/wap/loaders/productDetailsPage.ts b/wap/loaders/productDetailsPage.ts index 79404797f..f27beb603 100644 --- a/wap/loaders/productDetailsPage.ts +++ b/wap/loaders/productDetailsPage.ts @@ -32,8 +32,6 @@ const loader = async ( const itemListElement = toBreadcrumbList(data.estrutura.breadcrumb, baseUrl); - Deno.writeTextFileSync(`product_uappi.json`, JSON.stringify(data.conteudo)) - const product = toProduct(data.conteudo, baseUrl); return { From 1d7f9e51dff52a85aceb3fdb3e57b7159208ec6c Mon Sep 17 00:00:00 2001 From: Marcos Maia Date: Mon, 13 Jan 2025 12:11:10 -0300 Subject: [PATCH 4/6] novos dados --- wap/utils/transform.ts | 9 ++++++++- wap/utils/type.ts | 14 ++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/wap/utils/transform.ts b/wap/utils/transform.ts index adb20295d..8cbfd66bc 100644 --- a/wap/utils/transform.ts +++ b/wap/utils/transform.ts @@ -11,6 +11,7 @@ import { UnitPriceSpecification, } from "../../commerce/types.ts"; import { + Atributos, Breadcrumb, ConteudoMidias, Detalhes, @@ -218,7 +219,13 @@ export const toProduct = ( const sku = new URL(baseUrl).searchParams.get("sku"); - const images = product.midias.imagens.map((image) => ({ + const atributoSimples = (product.atributos as Atributos)?.simples?.valores?.find((v) => v.sku === sku) + + const attributeImages = atributoSimples ? product.midias.imagens.filter(image => image.idAtributoValor === atributoSimples.idAtributoValor) : [] + + console.log('LOG: product.midias', product.midias); + + const images = (attributeImages.length ? attributeImages : product.midias.imagens).map((image) => ({ "@type": "ImageObject" as const, name: image.label, description: image.descricao, diff --git a/wap/utils/type.ts b/wap/utils/type.ts index ce806d890..5a2b1c60e 100644 --- a/wap/utils/type.ts +++ b/wap/utils/type.ts @@ -45,16 +45,18 @@ export interface Detalhes { filtrosPreco: FiltrosPreco[]; filtrosDescontoPrecoPor: FiltroDescontoPrecoPor; selos: Selo[]; - atributos: Atributo[]; + atributos: Atributo; ordenacao: Ordenacao[]; } export interface Atributo { - id: number; - nome: string; - tipo: string; - valores: AtributoValores[]; - dominio?: string; + simples?: { + id: number; + nome: string; + tipo: string; + valores: AtributoValores[]; + dominio?: string; + } } export interface AtributoValores { From 3056b48cbac5b815edb3482741521f1c3f87df9b Mon Sep 17 00:00:00 2001 From: Marcos Maia Date: Mon, 13 Jan 2025 17:05:11 -0300 Subject: [PATCH 5/6] logs --- wap/utils/transform.ts | 326 +++++++++++++++++++++++------------------ 1 file changed, 180 insertions(+), 146 deletions(-) diff --git a/wap/utils/transform.ts b/wap/utils/transform.ts index 8cbfd66bc..849382be6 100644 --- a/wap/utils/transform.ts +++ b/wap/utils/transform.ts @@ -27,21 +27,19 @@ export const getUrl = (link: string, origin: string) => { export const toBreadcrumbList = ( breadcrumbs: Breadcrumb[], - baseUrl: string, + baseUrl: string ) => { - return breadcrumbs.slice(1).map((breadcrumb, index) => ( - { - "@type": "ListItem" as const, - item: getUrl(new URL(breadcrumb.url).pathname, baseUrl).href, - name: breadcrumb.label, - position: index, - } - )); + return breadcrumbs.slice(1).map((breadcrumb, index) => ({ + "@type": "ListItem" as const, + item: getUrl(new URL(breadcrumb.url).pathname, baseUrl).href, + name: breadcrumb.label, + position: index, + })); }; export const getProductStatus = ( status: WapProduto["status"], - estoque: number, + estoque: number ): ItemAvailability => { if (status === "disponivel" && estoque > 1) { return "https://schema.org/InStock"; @@ -52,7 +50,7 @@ export const getProductStatus = ( }; export const getPrices = ( - precos: WapProduto["precos"] | WapProductDatiled["precos"], + precos: WapProduto["precos"] | WapProductDatiled["precos"] ) => { const priceSpecification: UnitPriceSpecification[] = []; @@ -98,7 +96,7 @@ export const getPrices = ( export const toOffers = ( i: WapProduto | WapProductDatiled | ValorSimples, - status: WapProduto["status"], + status: WapProduto["status"] ) => { return { "@type": "AggregateOffer" as const, @@ -106,21 +104,23 @@ export const toOffers = ( lowPrice: i.precos.vista ?? null, priceCurrency: "BRL", offerCount: 1, - offers: [{ - "@type": "Offer" as const, - price: i.precos.por, - availability: getProductStatus(status, i.estoque), - inventoryLevel: { - value: i.estoque, + offers: [ + { + "@type": "Offer" as const, + price: i.precos.por, + availability: getProductStatus(status, i.estoque), + inventoryLevel: { + value: i.estoque, + }, + priceSpecification: getPrices(i.precos), }, - priceSpecification: getPrices(i.precos), - }], + ], }; }; export const toProduct = ( product: WapProduto | WapProductDatiled, - baseUrl: string, + baseUrl: string ): Product => { const additionalProperty: PropertyValue[] = []; @@ -182,10 +182,12 @@ export const toProduct = ( name: selo.nome, value: selo.label, valueReference: "SELOS", - image: [{ - "@type": "ImageObject", - url: selo.imagem, - }], + image: [ + { + "@type": "ImageObject", + url: selo.imagem, + }, + ], }); }); @@ -197,8 +199,7 @@ export const toProduct = ( value: carac.valor, valueReference: item.nome, }); - - }) + }); }); if (product?.filtros) { @@ -209,31 +210,39 @@ export const toProduct = ( value: filtro.label, identifier: String(filtro.idFiltro), valueReference: "FILTROS", - image: [{ - "@type": "ImageObject", - url: filtro.imagem, - }], + image: [ + { + "@type": "ImageObject", + url: filtro.imagem, + }, + ], }); }); } const sku = new URL(baseUrl).searchParams.get("sku"); - const atributoSimples = (product.atributos as Atributos)?.simples?.valores?.find((v) => v.sku === sku) + const atributoSimples = ( + product.atributos as Atributos + )?.simples?.valores?.find((v) => v.sku === sku); - const attributeImages = atributoSimples ? product.midias.imagens.filter(image => image.idAtributoValor === atributoSimples.idAtributoValor) : [] + const attributeImages = atributoSimples + ? product.midias.imagens.filter( + (image) => image.idAtributoValor === atributoSimples.idAtributoValor + ) + : []; - console.log('LOG: product.midias', product.midias); - - const images = (attributeImages.length ? attributeImages : product.midias.imagens).map((image) => ({ + const images = ( + attributeImages.length ? attributeImages : product.midias.imagens + ).map((image) => ({ "@type": "ImageObject" as const, name: image.label, description: image.descricao, url: image.arquivos.big ?? "", })); - const hasVariant: ProductLeaf[] = (product as WapProductDatiled).atributos - ?.simples?.valores.map((v) => ({ + const hasVariant: ProductLeaf[] = + (product as WapProductDatiled).atributos?.simples?.valores.map((v) => ({ "@type": "Product", productID: product.id.toString(), sku: v.sku, @@ -248,43 +257,51 @@ export const toProduct = ( name: (product as WapProductDatiled).atributos?.simples.nome, value: v.label, propertyID: String(v.idAtributoValor), - image: [{ "@type": "ImageObject", name: "imagem", url: v.imagem }, { - "@type": "ImageObject", - name: "imagemOriginal", - url: v.imagemOriginal, - }], + image: [ + { "@type": "ImageObject", name: "imagem", url: v.imagem }, + { + "@type": "ImageObject", + name: "imagemOriginal", + url: v.imagemOriginal, + }, + ], valueReference: "ATRIBUTO SIMPLES", }, ], })) ?? []; - (product as WapProductDatiled).atributos - ?.unico?.valores.forEach((v) => { - hasVariant.push({ - "@type": "Product", - productID: product.id.toString(), - sku: product.sku, - offers: toOffers(product, product.status), - name: product.nome, - url: `${ - getUrl(`/${product.rota.params.produto}`, baseUrl).href - }.html?sku=${product.sku}`, - additionalProperty: [ - { - "@type": "PropertyValue", - name: (product as WapProductDatiled).atributos?.unico.nome, - value: v.label, - propertyID: String(v.idAtributoValor), - image: [{ "@type": "ImageObject", name: "imagem", url: v.imagem }, { + console.log("LOG:", "aaaa", product?.atributos); + console.log("LOG:", "hasVariant", hasVariant); + + (product as WapProductDatiled).atributos?.unico?.valores.forEach((v) => { + hasVariant.push({ + "@type": "Product", + productID: product.id.toString(), + sku: product.sku, + offers: toOffers(product, product.status), + name: product.nome, + url: `${ + getUrl(`/${product.rota.params.produto}`, baseUrl).href + }.html?sku=${product.sku}`, + additionalProperty: [ + { + "@type": "PropertyValue", + name: (product as WapProductDatiled).atributos?.unico.nome, + value: v.label, + propertyID: String(v.idAtributoValor), + image: [ + { "@type": "ImageObject", name: "imagem", url: v.imagem }, + { "@type": "ImageObject", name: "imagemOriginal", url: v.imagemOriginal, - }], - valueReference: "ATRIBUTO UNICO", - }, - ], - }); + }, + ], + valueReference: "ATRIBUTO UNICO", + }, + ], }); + }); const selected = hasVariant.find((i) => i.sku == sku) ?? hasVariant[0]; @@ -311,22 +328,25 @@ export const toProduct = ( image: images.length ? images : [DEFAULT_IMAGE], category: (product as WapProductDatiled)?.categoria?.nome, isVariantOf, - aggregateRating: product.avaliacao.quantidade > 0 - ? { - "@type": "AggregateRating", - ratingValue: product.avaliacao.media, - ratingCount: product.avaliacao.quantidade, - reviewCount: product.avaliacao.avaliacoes?.length, - } - : undefined, + aggregateRating: + product.avaliacao.quantidade > 0 + ? { + "@type": "AggregateRating", + ratingValue: product.avaliacao.media, + ratingCount: product.avaliacao.quantidade, + reviewCount: product.avaliacao.avaliacoes?.length, + } + : undefined, review: product.avaliacao.avaliacoes?.map((avaliacao) => ({ "@type": "Review", // "@id": avaliacao.id, - author: [{ - "@type": "Author", - name: avaliacao.nome, - identifier: avaliacao.email, - }], + author: [ + { + "@type": "Author", + name: avaliacao.nome, + identifier: avaliacao.email, + }, + ], reviewBody: avaliacao?.comentario, datePublished: avaliacao?.data, itemReviewed: String(avaliacao?.produto?.id), @@ -342,34 +362,38 @@ export const toProduct = ( })), offers: toOffers(product, product.status), - isRelatedTo: (product as WapProductDatiled).combinacoes?.map(( - combinacao, - ) => toProduct(combinacao.produto, baseUrl)), - questions: (product as WapProductDatiled).perguntas?.map(( - pergunta, - ): Question => ({ - "@type": "Question", - answerCount: pergunta.respostas.length, - name: pergunta.pergunta, - text: pergunta.pergunta, - datePublished: pergunta.data, - suggestedAnswer: pergunta.respostas.map((resposta): Answer => ( - { - datePublished: resposta.data, - text: resposta.resposta, - author: [{ + isRelatedTo: (product as WapProductDatiled).combinacoes?.map((combinacao) => + toProduct(combinacao.produto, baseUrl) + ), + questions: (product as WapProductDatiled).perguntas?.map( + (pergunta): Question => ({ + "@type": "Question", + answerCount: pergunta.respostas.length, + name: pergunta.pergunta, + text: pergunta.pergunta, + datePublished: pergunta.data, + suggestedAnswer: pergunta.respostas.map( + (resposta): Answer => ({ + datePublished: resposta.data, + text: resposta.resposta, + author: [ + { + "@type": "Author", + identifier: resposta.email, + name: resposta.nome, + }, + ], + }) + ), + author: [ + { "@type": "Author", - identifier: resposta.email, - name: resposta.nome, - }], - } - )), - author: [{ - "@type": "Author", - identifier: pergunta.email, - name: pergunta.nome, - }], - })), + identifier: pergunta.email, + name: pergunta.nome, + }, + ], + }) + ), ...selected, }; }; @@ -377,11 +401,14 @@ export const toProduct = ( export const toFilter = ( filtro: { nome: string; - valores: Array< - { label?: string; nome?: string; url: string; ativo: boolean } - >; + valores: Array<{ + label?: string; + nome?: string; + url: string; + ativo: boolean; + }>; }, - baseUrl: string, + baseUrl: string ): Filter | null => { if (!filtro.valores.length) return null; @@ -390,63 +417,70 @@ export const toFilter = ( key: filtro.nome, label: filtro.nome, quantity: filtro.valores?.length ?? 0, - values: filtro.valores?.map((filterItem): FilterToggleValue => { - const filterURL = new URL(baseUrl); - filterURL.pathname = new URL(filterItem.url).pathname; - filterURL.search = new URL(filterItem.url).search; - - return { - quantity: 0, - value: filterItem.label ?? filterItem.nome ?? "", - label: filterItem.label ?? filterItem.nome ?? "", - selected: filterItem.ativo, - url: filterURL.href, - }; - }) ?? [], + values: + filtro.valores?.map((filterItem): FilterToggleValue => { + const filterURL = new URL(baseUrl); + filterURL.pathname = new URL(filterItem.url).pathname; + filterURL.search = new URL(filterItem.url).search; + + return { + quantity: 0, + value: filterItem.label ?? filterItem.nome ?? "", + label: filterItem.label ?? filterItem.nome ?? "", + selected: filterItem.ativo, + url: filterURL.href, + }; + }) ?? [], }; }; -export const toFilters = ( - details: Detalhes, - baseUrl: string, -): Filter[] => { +export const toFilters = (details: Detalhes, baseUrl: string): Filter[] => { const filters = []; const fromFiltros = details.filtros.map((filtro) => toFilter(filtro, baseUrl) ); - const fromMarcas = toFilter({ - nome: "marca", - valores: details.marcas, - }, baseUrl); + const fromMarcas = toFilter( + { + nome: "marca", + valores: details.marcas, + }, + baseUrl + ); const fromAttributes = details.atributos.map((filtro) => toFilter(filtro, baseUrl) ); - const fromPrecos = toFilter({ - nome: "preco", - valores: details.filtrosPreco.map((i) => ({ - nome: `${i.de}-${i.ate}`, - ...i, - })), - }, baseUrl); + const fromPrecos = toFilter( + { + nome: "preco", + valores: details.filtrosPreco.map((i) => ({ + nome: `${i.de}-${i.ate}`, + ...i, + })), + }, + baseUrl + ); - const fromDescontoPrecoPor = toFilter({ - nome: "Desconto Preco Por", - valores: Object.values(details.filtrosDescontoPrecoPor).map((i) => ({ - nome: `${i.de}-${i.ate}`, - ...i, - })), - }, baseUrl); + const fromDescontoPrecoPor = toFilter( + { + nome: "Desconto Preco Por", + valores: Object.values(details.filtrosDescontoPrecoPor).map((i) => ({ + nome: `${i.de}-${i.ate}`, + ...i, + })), + }, + baseUrl + ); filters.push( ...fromFiltros, fromMarcas, ...fromAttributes, fromPrecos, - fromDescontoPrecoPor, + fromDescontoPrecoPor ); return filters.filter((f): f is Filter => Boolean(f)); From 54a4dfba29b23afd14c83836319f5f862d86b1f8 Mon Sep 17 00:00:00 2001 From: Marcos Maia Date: Sun, 9 Mar 2025 00:52:00 -0300 Subject: [PATCH 6/6] staging 09 --- wap/loaders/productListingPage.ts | 2 ++ wap/utils/transform.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/wap/loaders/productListingPage.ts b/wap/loaders/productListingPage.ts index 7770a807e..919188706 100644 --- a/wap/loaders/productListingPage.ts +++ b/wap/loaders/productListingPage.ts @@ -142,6 +142,8 @@ const loader = async ( const filters = toFilters(data.conteudo.detalhes, baseUrl); + Deno.writeTextFileSync("produtosApp.json", JSON.stringify(data.conteudo.produtos)); + const products = data.conteudo.produtos.map((produto) => toProduct(produto, baseUrl) ); diff --git a/wap/utils/transform.ts b/wap/utils/transform.ts index 849382be6..70de4469d 100644 --- a/wap/utils/transform.ts +++ b/wap/utils/transform.ts @@ -271,7 +271,7 @@ export const toProduct = ( })) ?? []; console.log("LOG:", "aaaa", product?.atributos); - console.log("LOG:", "hasVariant", hasVariant); + console.log('LOG:','product.nome', product.nome); (product as WapProductDatiled).atributos?.unico?.valores.forEach((v) => { hasVariant.push({