diff --git a/CHANGELOG.md b/CHANGELOG.md index aa718ab441..def949725f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Change translation from jp-JP to ja-JP - @gibkigonzo (#3824) - Fixed ecosystem config for pm2 - @andrzejewsky (#3842) - Fixed `mappingFallback` for extending modules - @andrzejewsky (#3822) +- Fixed some potential mutations of Config object in `catalog` and `catalog-next` - @grimasod (#3843) ### Changed / Improved - Changed pre commit hook to use NODE_ENV production to check for debugger statements - @resubaka (#3686) diff --git a/core/modules/catalog-next/store/category/actions.ts b/core/modules/catalog-next/store/category/actions.ts index 53ab1fa6e2..06b514ef47 100644 --- a/core/modules/catalog-next/store/category/actions.ts +++ b/core/modules/catalog-next/store/category/actions.ts @@ -20,6 +20,7 @@ import { preConfigureProduct } from '@vue-storefront/core/modules/catalog/helper import chunk from 'lodash-es/chunk' import Product from 'core/modules/catalog/types/Product'; import omit from 'lodash-es/omit' +import cloneDeep from 'lodash-es/cloneDeep' import config from 'config' import { parseCategoryPath } from '@vue-storefront/core/modules/breadcrumbs/helpers' @@ -140,7 +141,7 @@ const actions: ActionTree = { categorySearchOptions.filters.id = searchedIds.filter(categoryId => !getters.getCategoriesMap[categoryId] && !getters.getNotFoundCategoryIds.includes(categoryId)) } if (!searchingByIds || categorySearchOptions.filters.id.length) { - categorySearchOptions.filters = Object.assign(config.entities.category.filterFields, categorySearchOptions.filters) + categorySearchOptions.filters = Object.assign(cloneDeep(config.entities.category.filterFields), categorySearchOptions.filters ? cloneDeep(categorySearchOptions.filters) : {}) const categories = await CategoryService.getCategories(categorySearchOptions) const notFoundCategories = searchedIds.filter(categoryId => !categories.some(cat => cat.id === parseInt(categoryId))) @@ -176,7 +177,7 @@ const actions: ActionTree = { let resultFilters = aggregationFilters const filtersKeys = Object.keys(filters) if (categoryMappedFilters && filtersKeys.length) { - resultFilters = Object.assign({}, categoryMappedFilters, omit(aggregationFilters, filtersKeys)) + resultFilters = Object.assign(cloneDeep(categoryMappedFilters), cloneDeep(omit(aggregationFilters, filtersKeys))) } commit(types.CATEGORY_SET_CATEGORY_FILTERS, {category, filters: resultFilters}) }, diff --git a/core/modules/catalog/store/product/actions.ts b/core/modules/catalog/store/product/actions.ts index 671f8b84c3..f38cc3577f 100644 --- a/core/modules/catalog/store/product/actions.ts +++ b/core/modules/catalog/store/product/actions.ts @@ -19,6 +19,7 @@ import { optionLabel } from '../../helpers/optionLabel' import { isOnline } from '@vue-storefront/core/lib/search' import omit from 'lodash-es/omit' import trim from 'lodash-es/trim' +import cloneDeep from 'lodash-es/cloneDeep' import uniqBy from 'lodash-es/uniqBy' import rootStore from '@vue-storefront/core/store' import RootState from '@vue-storefront/core/types/RootState' @@ -684,7 +685,7 @@ const actions: ActionTree = { if (product && product.category_ids) { let currentCategory = rootGetters['category-next/getCurrentCategory'] // use current category, if set if (!currentCategory || !currentCategory.id || !product.category_ids.includes(currentCategory.id.toString())) { - const categoryFilters = Object.assign({ 'id': product.category_ids }, config.entities.category.breadcrumbFilterFields) + const categoryFilters = Object.assign({ 'id': [...product.category_ids] }, cloneDeep(config.entities.category.breadcrumbFilterFields)) const categories = await dispatch('category-next/loadCategories', {filters: categoryFilters}, { root: true }) currentCategory = categories.sort((a, b) => (a.level > b.level) ? -1 : 1)[0] // sort starting by deepest level }