Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fetchCategory = categoryId => (dispatch, getState) => {
const state = getState();
const category = state.category.categoriesById[categoryId];
if (!shouldFetchData(category)) {
/**
* Child categories are maybe missing.
* So we need to check it (check happens inside fetchCategoryChildren).
* This is the case if we got categories from getRootCategory
*/
dispatch(fetchCategoryChildren(categoryId));
return;
}
// No data at all. So we have the fetch the category with children included
dispatch(requestCategory(categoryId));
new PipelineRequest('shopgate.catalog.getCategory')
.setInput({
categoryId,
includeChildren: true,
const fetchCategory = categoryId => (dispatch, getState) => {
const state = getState();
const category = state.category.categoriesById[categoryId];
if (!shouldFetchData(category)) {
/**
* Child categories are maybe missing.
* So we need to check it (check happens inside fetchCategoryChildren).
* This is the case if we got categories from getRootCategory
*/
if (category.childrenCount) {
dispatch(fetchCategoryChildren(categoryId));
}
return Promise.resolve(category);
}
// No data at all. So we have the fetch the category with children included
dispatch(requestCategory(categoryId));
return new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_CATEGORY)
const fetchSearchSuggestions = () => (dispatch, getState) => {
const state = getState();
const searchPhrase = getSearchPhrase(state);
const cachedSuggestions = getCurrentSearchSuggestionsObject(state);
if (!shouldFetchData(cachedSuggestions)) {
return;
}
dispatch(requestSearchSuggestions(searchPhrase));
new PipelineRequest('getSearchSuggestions')
.setInput({ searchPhrase })
.dispatch()
.then(({ suggestions }) => {
dispatch(receiveSearchSuggestions(searchPhrase, removeHighlightingPlaceholders(suggestions)));
});
};
(dispatch, getState) => {
const pipeline = SHOPGATE_CATALOG_GET_PRODUCT_RELATIONS;
const hash = generateProductRelationsHash({
productId,
type,
limit,
});
const currentState = getProductRelationsState(getState())[hash];
if (!shouldFetchData(currentState, 'productIds')) {
return null;
}
dispatch(requestProductRelations({ hash }));
const request = new PipelineRequest(pipeline)
.setInput({
productId,
type,
limit,
})
.dispatch();
request
.then((payload) => {
const { relations } = payload;
const fetchProductOptions = productId => (dispatch, getState) => {
const state = getState();
const cachedData = state.product.optionsByProductId[productId];
if (!shouldFetchData(cachedData)) {
return;
}
dispatch(requestProductOptions(productId));
new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT_OPTIONS)
.setInput({ productId })
.dispatch()
.then(result => dispatch(receiveProductOptions(productId, result.options)))
.catch((error) => {
logger.error(error);
dispatch(errorProductOptions(productId, error.code));
});
};
const missingIds = productIds.filter(id => shouldFetchData(products[id]));
const getUserReview = productId => (dispatch, getState) => {
const data = getState().reviews.userReviewsByProductId[productId];
if (!shouldFetchData(data)) {
return new Promise(resolve => resolve());
}
dispatch(requestUserReview(productId));
const request = new PipelineRequest('getUserReview')
.setHandledErrors([EUNKNOWN, EACCESS])
.setInput({
productId,
})
.dispatch();
request
.then(result => dispatch(receiveUserReview(productId, result)))
.catch(() => {
dispatch(errorUserReview(productId));
});
const fetchUserReview = productId => (dispatch, getState) => {
const data = getState().reviews.userReviewsByProductId[productId];
if (!shouldFetchData(data)) {
return new Promise(resolve => resolve());
}
dispatch(requestUserReview(productId));
const request = new PipelineRequest(pipelines.SHOPGATE_USER_GET_REVIEW)
.setErrorBlacklist([EUNKNOWN, EACCESS])
.setInput({
productId,
})
.dispatch();
request
.then(result => dispatch(receiveUserReview(productId, result)))
.catch(() => {
dispatch(errorUserReview(productId));
});
const getProduct = (productId, forceFetch = false) => (dispatch, getState) => {
const state = getState();
const product = getProductById(state, productId);
if (!forceFetch && !shouldFetchData(product)) {
if (product.productData) {
dispatch(processProductFlags(product.productData))
.then(() => {
dispatch(receiveProductCached(product.productData));
});
}
return;
}
dispatch(requestProduct(productId));
new PipelineRequest('shopgate.catalog.getProduct')
.setInput({ productId })
.dispatch()
.then((result) => {
const fetchProduct = (productId, forceFetch = false) => (dispatch, getState) => {
const state = getState();
const product = getProductById(state, { productId });
if (!forceFetch && !shouldFetchData(product)) {
if (product.productData) {
dispatch(receiveProductCached(product.productData));
}
return;
}
const requestParams = {
...configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS),
productId,
};
dispatch(requestProduct(productId, forceFetch));
new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT)
.setInput(requestParams)