UNPKG

@shopgate/engage

Version:
9 lines 3.61 kB
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import{connect}from'react-redux';import{hasProductVariants,isProductOrderable,makeIsBaseProductActive}from'@shopgate/engage/product';import{DIRECT_SHIP,ROPIS,BOPIS}from"../../constants";import{makeGetEnabledFulfillmentMethods,makeGetFulfillmentPaths,makeUseLocationFulfillmentMethods}from"../../../core/config";import{getProductShowAlternativeLocation}from"../../../core/selectors";import{MERCHANT_SETTINGS_PRODUCT_SHOW_ALTERNATIVE_LOCATION}from"../../../core/constants";import{makeIsFulfillmentSelectorMethodEnabled,getPreferredLocation,makeGetLocationInventory,makeGetLocationFulfillmentMethods,getPreferredFulfillmentMethod,getProductFulfillmentMethods,getUserSearch}from"../../selectors";import{storeFulfillmentMethod}from"../../action-creators";/** * @return {Function} The extended component props. */function makeMapStateToProps(){/* eslint-disable require-jsdoc */var getLocationCode=function getLocationCode(state,props){var _getPreferredLocation;return(_getPreferredLocation=getPreferredLocation(state,props))===null||_getPreferredLocation===void 0?void 0:_getPreferredLocation.code;};var getProductCode=function getProductCode(_,props){return props.variantId||props.productId||null;};/* eslint-enable require-jsdoc */var getFulfillmentPaths=makeGetFulfillmentPaths();var isDirectShipEnabled=makeIsFulfillmentSelectorMethodEnabled(getLocationCode,getProductCode,DIRECT_SHIP);var isROPISEnabled=makeIsFulfillmentSelectorMethodEnabled(getLocationCode,getProductCode,ROPIS,// Set to true when fulfillment methods shall not be disabled that are not supported by location false);var isBOPISEnabled=makeIsFulfillmentSelectorMethodEnabled(getLocationCode,getProductCode,BOPIS,// Set to true when fulfillment methods shall not be disabled that are not supported by location false);var getInventory=makeGetLocationInventory(getLocationCode,getProductCode);var getEnabledFulfillmentMethods=makeGetEnabledFulfillmentMethods();var getLocationFulfillmentMethods=makeGetLocationFulfillmentMethods(getLocationCode);var isBaseProductActive=makeIsBaseProductActive();var useLocationFulfillmentMethods=makeUseLocationFulfillmentMethods();/** * @param {Object} state The application state. * @param {Object} props The component props. * @returns {Object} */return function(state,props){var hasVariants=hasProductVariants(state,props);var baseProductActive=isBaseProductActive(state,props);return{merchantSettings:_defineProperty({},MERCHANT_SETTINGS_PRODUCT_SHOW_ALTERNATIVE_LOCATION,getProductShowAlternativeLocation(state)),fulfillmentPaths:getFulfillmentPaths(state),shopFulfillmentMethods:getEnabledFulfillmentMethods(state),productFulfillmentMethods:getProductFulfillmentMethods(state,props),locationFulfillmentMethods:getLocationFulfillmentMethods(state,props),useLocationFulfillmentMethods:useLocationFulfillmentMethods(state,props),userFulfillmentMethod:getPreferredFulfillmentMethod(state,props),preferredLocation:getPreferredLocation(state,props),inventory:getInventory(state,props),isDirectShipEnabled:isDirectShipEnabled(state,props),isROPISEnabled:isROPISEnabled(state,props),isBOPISEnabled:isBOPISEnabled(state,props),isOrderable:isProductOrderable(state,props)||!!hasVariants,isReady:hasVariants!==null&&(!hasVariants||!baseProductActive),userSearch:getUserSearch(state)};};}var mapDispatchToProps={storeFulfillmentMethod:storeFulfillmentMethod};export default connect(makeMapStateToProps,mapDispatchToProps);