@shopgate/engage
Version:
Shopgate's ENGAGE library.
7 lines • 1.37 kB
JavaScript
import{logger}from'@shopgate/pwa-core/helpers';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{mutable}from'@shopgate/pwa-common/helpers/redux';import{requestProductInventories,receiveProductInventories,errorProductInventories}from"../action-creators";import{SHOPGATE_STOREFRONT_GET_PRODUCT_INVENTORIES}from"../constants";/**
* Fetches inventories for a product
* @param {string} productCode The product ID to fetch inventories for.
* @param {Object} [params={}] Optional params for the inventories request.
* @param {string[]} params.locationCodes A list of location codes.
* @returns {Function} A redux thunk.
*/function fetchProductInventories(productCode){var params=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return function(dispatch){var filters={locationCodes:params.locationCodes,productCode:productCode};dispatch(requestProductInventories(productCode,filters.locationCodes));var request=new PipelineRequest(SHOPGATE_STOREFRONT_GET_PRODUCT_INVENTORIES).setInput(filters).dispatch();request.then(function(result){dispatch(receiveProductInventories(productCode,filters.locationCodes,result.inventories));})["catch"](function(error){logger.error(error);dispatch(errorProductInventories(productCode,error.code));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchProductInventories);