@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
5 lines • 1.27 kB
JavaScript
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import{SHOPGATE_CATALOG_GET_PRODUCT_SHIPPING}from"../constants/Pipelines";import requestProductShipping from"../action-creators/requestProductShipping";import receiveProductShipping from"../action-creators/receiveProductShipping";import errorProductShipping from"../action-creators/errorProductShipping";/**
* Retrieves product shipping from the store.
* @param {string} productId The product ID for which the product shipping is requested.
* @return {Function} A Redux Thunk
*/function fetchProductShipping(productId){return function(dispatch,getState){var state=getState();var shipping=state.product.shippingByProductId[productId];if(!shouldFetchData(shipping)){return Promise.resolve(null);}dispatch(requestProductShipping(productId));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT_SHIPPING).setInput({productId:productId}).dispatch();request.then(function(result){dispatch(receiveProductShipping(productId,result.shipping));})["catch"](function(error){dispatch(errorProductShipping(productId,error.code));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchProductShipping);