Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Prevent Featured Product block from breaking when product is out of…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
albarin and tomasztunik authored Mar 31, 2022
1 parent a0ffa4b commit 3c0e0af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions assets/js/editor-components/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion assets/js/hocs/with-product-variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const withProductVariations = createHigherOrderComponent(
p.variations &&
p.variations.find( ( { id } ) => id === variationId )
);
return parentProduct[ 0 ].id;
return parentProduct[ 0 ]?.id;
}

getExpandedProduct() {
Expand Down Expand Up @@ -186,6 +186,7 @@ const withProductVariations = createHigherOrderComponent(
showVariations: false,
};
}

return WrappedComponent;
},
'withProductVariations'
Expand Down

0 comments on commit 3c0e0af

Please sign in to comment.