@shopgate/engage
Version:
Shopgate's ENGAGE library.
96 lines (91 loc) • 2.32 kB
JavaScript
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 const buildFetchCategoryProductsParams = () => {
if (!isBeta()) {
return {
params: {}
};
}
const scheduled = buildShowScheduledParams();
return {
params: {
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 const buildFetchSearchResultsParams = buildFetchCategoryProductsParams;
/**
* Set default params for fetching products
*/
export const setDefaultProductFetchParams = () => {
if (!isBeta()) {
return;
}
configuration.set(DEFAULT_PRODUCTS_FETCH_PARAMS, {
characteristics: true
});
};
/**
* Provides the settings for ProductImages
* @return {Object}
*/
export const getProductImageSettings = () => {
const appImages = getThemeSettings('AppImages');
return {
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 const loadProductImage = (src, resolution = null) => {
let res = resolution;
if (!res) {
const {
HeroImage: resolutions
} = getProductImageSettings();
[res] = resolutions;
}
return loadImage(getFullImageSource(src, res));
};