Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Category
case 5: {
hashParams = {
id,
categoryId: value,
sort: transformedSort,
};
break;
}
default:
}
// Generate the hash string.
return generateResultHash(hashParams, true, false);
};
const fetchFilters = () => (dispatch, getState) => {
const state = getState();
const params = buildFilterParams(state);
const hash = generateResultHash({
pipeline: pipelines.SHOPGATE_CATALOG_GET_FILTERS,
...params,
}, false, false);
const result = getFilterResults(state)[hash];
if (!shouldFetchFilters(result)) {
return;
}
// We need to process the params to handle edge cases in the pipeline params.
const requestParams = processParams(params);
if (Object.keys(requestParams).length === 0) {
logger.error(`Attempt to call ${pipelines.SHOPGATE_CATALOG_GET_FILTERS} pipeline without parameters - aborted`);
return;
const { offset, limit, ...hashParams } = params;
const { sort = DEFAULT_SORT } = hashParams;
let getProductsRequestParams;
if (pipeline === pipelines.SHOPGATE_CATALOG_GET_PRODUCTS) {
getProductsRequestParams = configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS);
}
// We need to process the params to handle edge cases in the pipeline params.
const requestParams = {
...getProductsRequestParams,
...processParams(params, filters, includeSort, includeFilters),
};
const hash = generateResultHash({
pipeline,
sort,
...hashParams,
...(filters && Object.keys(filters).length) && { filters },
...id && { id },
}, includeSort, includeFilters);
const result = state.product.resultsByHash[hash];
let requiredProductCount = null;
// Only set a required number of products if both offset and limit are valid.
if (isNumber(offset) && isNumber(limit)) {
requiredProductCount = offset + limit;
}
// Stop if we don't need to get any data.
export const getFilters = () => (dispatch, getState) => {
const state = getState();
const activeFilters = getActiveFilters(state);
const params = buildFilterParams(state);
const hash = generateResultHash({
pipeline: 'getFilters',
...params,
}, false);
const result = getAvailableFiltersStack(state)[hash];
if (!shouldFetchFilters(result)) {
return;
}
// We need to process the params to handle edge cases in the pipeline params.
const requestParams = processParams(params, activeFilters);
dispatch(requestFilters(hash));
new PipelineRequest('getFilters')
.setInput(requestParams)
(searchPhrase, sort, results) => {
const hash = searchPhrase && generateResultHash({
sort,
searchPhrase,
});
if (!hash || !results[hash]) {
return null;
}
return results[hash].totalResultCount;
}
);
(results, categoryId, searchPhrase) => {
const hash = generateResultHash({
pipeline: pipelines.SHOPGATE_CATALOG_GET_FILTERS,
...categoryId && { categoryId: hex2bin(categoryId) },
...searchPhrase && { searchPhrase },
}, false, false);
return (results[hash] && results[hash].filters) || null;
}
);
const fetchReviews = (productId, limit = 2, offset = 0, sort = SORT_DATE_DESC) => (dispatch) => {
const hash = generateResultHash({
pipeline: 'shopgate.catalog.getProductReviews',
productId,
}, false);
dispatch(requestProductReviewsList(hash));
/**
* For testing purposes there's need to keep and return the promise reference, not a result of
* chained functions.
* Otherwise test case won't get the original resolver.
* To get more insights, please take a look at ../spec.js.
* @type {Promise}
*/
const request = new PipelineRequest('shopgate.catalog.getProductReviews')
.setInput({
productId,
limit,
) => (dispatch) => {
const hash = generateResultHash({
pipeline: pipelines.SHOPGATE_CATALOG_GET_PRODUCT_REVIEWS,
productId,
}, false);
dispatch(requestProductReviewsList(hash));
/**
* For testing purposes there's need to keep and return the promise reference, not a result of
* chained functions.
* Otherwise test case won't get the original resolver.
* To get more insights, please take a look at ../spec.js.
* @type {Promise}
*/
const request = new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT_REVIEWS)
.setInput({
productId,
limit,
const getResultHash = state => generateResultHash({
pipeline: 'getLiveshoppingProducts',
sort: getSortOrder(state),
}, true, false);
(productId, reviewsState) => {
const hash = generateResultHash({
pipeline: 'shopgate.catalog.getProductReviews',
productId,
}, false);
if (reviewsState.hasOwnProperty(hash)) {
return reviewsState[hash];
}
return null;
}
);