From 1064bac1993e5e96a55fe684dd0de88087bed6b1 Mon Sep 17 00:00:00 2001 From: Carina Hoffmann Date: Mon, 28 May 2018 15:06:21 +0200 Subject: [PATCH] PWA-437: Favourite list has issues with "out of stock" items - add product stock info selectors --- .../commerce/product/selectors/product.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libraries/commerce/product/selectors/product.js b/libraries/commerce/product/selectors/product.js index 9b8e3fe45b..5c3965e5c8 100644 --- a/libraries/commerce/product/selectors/product.js +++ b/libraries/commerce/product/selectors/product.js @@ -310,6 +310,21 @@ export const getCurrentProductStock = createSelector( } ); +/** + * Retrieves the product stock information. + * @param {Object} state The current application state. + * @return {Object|null} + */ +export const getProductStockInfo = createSelector( + getProductById, + (product) => { + if (!product || !product.productData) { + return null; + } + return product.productData.stock; + } +) + /** * Retrieves the current product orderable information. * @param {Object} state The current application state. @@ -326,6 +341,16 @@ export const isProductOrderable = createSelector( } ); +/** + * Retrieves the product orderable information. + * @param {Object} state The current application state. + * @return {boolean} + */ +export const isOrderable = createSelector( + getProductStockInfo, + stockInfo => stockInfo && stockInfo.orderable +); + /** * Selects the product shipping state. * @param {Object} state The current application state.