From 9d95ad71854d3376959173618cef394f4ec82caa Mon Sep 17 00:00:00 2001 From: Steffany-Martins Date: Wed, 31 May 2023 14:27:17 -0300 Subject: [PATCH 1/2] chore: add hideUnavailableItems to props loader and return null product id --- functions/vtexLegacyRelatedProductsLoader.ts | 7 ++++++- packs/vtex/loaders/legacy/relatedProductsLoader.ts | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/functions/vtexLegacyRelatedProductsLoader.ts b/functions/vtexLegacyRelatedProductsLoader.ts index 5895e8ab..dfeed3eb 100644 --- a/functions/vtexLegacyRelatedProductsLoader.ts +++ b/functions/vtexLegacyRelatedProductsLoader.ts @@ -16,6 +16,10 @@ export interface Props { * @description: number of related products */ count?: number; + /** + * @description remove unavailable items from result + */ + hideUnavailableItems?: boolean; } /** @@ -30,13 +34,14 @@ const loaderV0: LoaderFunction< > = async ( req, ctx, - { crossSelling, count }, + { crossSelling, count, hideUnavailableItems }, ) => { const data = await loader( { slug: ctx.params.slug, crossSelling, count, + hideUnavailableItems, }, req, ctx.state, diff --git a/packs/vtex/loaders/legacy/relatedProductsLoader.ts b/packs/vtex/loaders/legacy/relatedProductsLoader.ts index c5f774b1..fdcc69ee 100644 --- a/packs/vtex/loaders/legacy/relatedProductsLoader.ts +++ b/packs/vtex/loaders/legacy/relatedProductsLoader.ts @@ -85,7 +85,8 @@ async function loader( const productId = await getProductGroupID(props); if (!productId) { - throw new Error("Missing props. Please fill: slug or id"); + // throw new Error("Missing props. Please fill: slug or id"); + return null; } const vtexRelatedProducts = await fetchAPI( From 176c60c72bb3048527f1919bfa501737265cddb4 Mon Sep 17 00:00:00 2001 From: Steffany-Martins Date: Wed, 31 May 2023 16:52:24 -0300 Subject: [PATCH 2/2] chore: remove the comment about error --- packs/vtex/loaders/legacy/relatedProductsLoader.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packs/vtex/loaders/legacy/relatedProductsLoader.ts b/packs/vtex/loaders/legacy/relatedProductsLoader.ts index fdcc69ee..3e8fde97 100644 --- a/packs/vtex/loaders/legacy/relatedProductsLoader.ts +++ b/packs/vtex/loaders/legacy/relatedProductsLoader.ts @@ -85,7 +85,6 @@ async function loader( const productId = await getProductGroupID(props); if (!productId) { - // throw new Error("Missing props. Please fill: slug or id"); return null; }