From 3c0e0afb29387138f30fa6ebe2076324663f260d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Thu, 31 Mar 2022 15:24:10 +0200 Subject: [PATCH] Prevent `Featured Product` block from breaking when product is out of stock + hidden from catalog (#6166) * Prevent accessing the first element of the `parentProduct` array if empty * Include all products regardless of their `stock_status` By default, the `/wc/store/v1/products` endpoint does not return products with `outofstock` stock status. We want the users to be able to select any product regardless of its stock status, we need to explicitly request them using the `stock_status` query param. * Use the optional chaining operator Co-authored-by: Tomasz Tunik --- assets/js/editor-components/utils/index.js | 1 + assets/js/hocs/with-product-variations.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/js/editor-components/utils/index.js b/assets/js/editor-components/utils/index.js index e133a9c749e..2b47a47b4ff 100644 --- a/assets/js/editor-components/utils/index.js +++ b/assets/js/editor-components/utils/index.js @@ -25,6 +25,7 @@ const getProductsRequests = ( { const defaultArgs = { per_page: isLargeCatalog ? 100 : 0, catalog_visibility: 'any', + stock_status: [ 'instock', 'outofstock', 'onbackorder' ], search, orderby: 'title', order: 'asc', diff --git a/assets/js/hocs/with-product-variations.js b/assets/js/hocs/with-product-variations.js index cefdfa9dd20..36c4ecc80ae 100644 --- a/assets/js/hocs/with-product-variations.js +++ b/assets/js/hocs/with-product-variations.js @@ -124,7 +124,7 @@ const withProductVariations = createHigherOrderComponent( p.variations && p.variations.find( ( { id } ) => id === variationId ) ); - return parentProduct[ 0 ].id; + return parentProduct[ 0 ]?.id; } getExpandedProduct() { @@ -186,6 +186,7 @@ const withProductVariations = createHigherOrderComponent( showVariations: false, }; } + return WrappedComponent; }, 'withProductVariations'