@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 requestProductImages from"../action-creators/requestProductImages";import{SHOPGATE_CATALOG_GET_PRODUCT_IMAGES}from"../constants/Pipelines";import receiveProductImages from"../action-creators/receiveProductImages";import errorProductImages from"../action-creators/errorProductImages";import{getProductImagesState}from"../selectors/product";/**
* Maybe requests images for a product from server.
* @param {string} productId The product ID.
* @return {Function} The dispatched action.
*/function fetchProductImages(productId){return function(dispatch,getState){var productImages=getProductImagesState(getState())[productId];if(!shouldFetchData(productImages)){return Promise.resolve(null);}dispatch(requestProductImages(productId));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT_IMAGES).setInput({productId:productId}).setVersion(3).dispatch();request.then(function(result){dispatch(receiveProductImages(productId,result.images));})["catch"](function(error){dispatch(errorProductImages(productId,error.code));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchProductImages);