UNPKG

@shopgate/engage

Version:
17 lines 3.12 kB
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import configuration from'@shopgate/pwa-common/collections/Configuration';import{DEFAULT_PRODUCTS_FETCH_PARAMS}from'@shopgate/pwa-common/constants/Configuration';import{getFullImageSource,isBeta,loadImage}from'@shopgate/engage/core/helpers';import{getThemeSettings}from'@shopgate/engage/core/config';import{buildShowScheduledParams}from"../components/EffectivityDates/helpers";export*from'@shopgate/pwa-common-commerce/product/helpers';export*from"../components/Media/helpers";export*from"./redirects";/** * Build params to fetch category products * @returns {undefined|{params: Object}} */export var buildFetchCategoryProductsParams=function buildFetchCategoryProductsParams(){if(!isBeta()){return{params:{}};}var scheduled=buildShowScheduledParams();return _extends({params:_extends({characteristics:true},scheduled.params)},scheduled.cachedTime&&{cachedTime:scheduled.cachedTime});};/** * Build params to fetch search products. Same as category for now * @returns {undefined|{params: Object}} */export var buildFetchSearchResultsParams=buildFetchCategoryProductsParams;/** * Set default params for fetching products */export var setDefaultProductFetchParams=function setDefaultProductFetchParams(){if(!isBeta()){return;}configuration.set(DEFAULT_PRODUCTS_FETCH_PARAMS,{characteristics:true});};/** * Provides the settings for ProductImages * @return {Object} */export var getProductImageSettings=function getProductImageSettings(){var appImages=getThemeSettings('AppImages');return _extends({quality:75,fillColor:'FFFFFF,1',HeroImage:[{width:440,height:440},{width:1024,height:1024}],GalleryImage:[{width:1024,height:1024},{width:2048,height:2048}],ListImage:[{width:440,height:440}]},appImages);};/** * Load product image with given resolution * @param {string} src . * @param {Object} resolution . * @returns {Promise} */export var loadProductImage=function loadProductImage(src){var resolution=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var res=resolution;if(!res){var _getProductImageSetti2=getProductImageSettings(),resolutions=_getProductImageSetti2.HeroImage;var _resolutions=_slicedToArray(resolutions,1);res=_resolutions[0];}return loadImage(getFullImageSource(src,res));};