Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Refactor catalog module #2890

Merged
merged 90 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
5d2827c
prepare module draft
patzick May 8, 2019
3889092
add default values
patzick May 9, 2019
9d2462a
init module actions
patzick May 9, 2019
16ca33e
move helper from old module
patzick May 9, 2019
0207857
getting available filters
patzick May 9, 2019
087d45e
invoke search with current filters
patzick May 9, 2019
e834b21
current category from getter
patzick May 9, 2019
d372696
default value as string
patzick May 9, 2019
59f2130
add todo for multiple filters
patzick May 9, 2019
8a9d28d
switching search filters
patzick May 9, 2019
d2b4664
switching filters query
patzick May 9, 2019
23e70d7
multiple dilters draft and reseting filters
patzick May 9, 2019
c60508d
migrate filter components
patzick May 9, 2019
54a231b
migrate category page
patzick May 9, 2019
f45fe5b
filters and currentCategory as getters
patzick May 10, 2019
d027a4c
active filters
patzick May 10, 2019
8e71fdf
recomputing getters
patzick May 10, 2019
8f9e795
ui active filters
patzick May 10, 2019
f5cdd82
add sorty by property
patzick May 10, 2019
0a9f7d5
system filters not visible on search filters
patzick May 13, 2019
f979051
get turned off by default
patzick May 13, 2019
fece9d5
add category breadcrumbs
patzick May 13, 2019
fb380e7
stop using of sidebar mixin
patzick May 13, 2019
bd32c8c
add multiple filters support
patzick May 15, 2019
9084808
merge develop
patzick May 15, 2019
487a847
moved filter logic to mixin
patzick May 15, 2019
a819f6f
refactor calculate getters
patzick May 15, 2019
25eabd7
move logic to getters
patzick May 16, 2019
652afe0
move logic to directory
patzick May 16, 2019
767aa6d
change loadCategory invocation
patzick May 16, 2019
4ee0279
change router as separate action
patzick May 19, 2019
97e0981
add category service
patzick May 19, 2019
adc60ad
loading categories
patzick May 19, 2019
d97b2a1
change filter method with tests
patzick May 19, 2019
eab2243
extract getFiltersFromQuery with tests
patzick May 19, 2019
8fd4f42
add support for multiple prices with tests
patzick May 20, 2019
af8db3a
Merge branch 'develop' into magento-catalog
patzick May 20, 2019
98034ef
Merge branch 'magento-catalog' of https://github.com/patzick/vue-stor…
patzick May 20, 2019
35293e3
add support for filters as query and path params
patzick May 20, 2019
b47b34b
filters per category
patzick May 20, 2019
7d4633b
refactor -magento to -next
patzick May 22, 2019
e7bdcf2
merge develop
patzick May 29, 2019
93d2588
support finding configurable child with multiple filters
patzick May 30, 2019
771d734
configure fetched products
patzick May 30, 2019
fa52a84
load category filters before picking filters
patzick May 30, 2019
f0a7259
Merge branch 'develop' into magento-catalog
patzick May 30, 2019
738ddce
test caching on server
patzick Jun 3, 2019
6208010
improve service worker catalog cache
patzick Jun 3, 2019
4a687c5
use filters on product page
patzick Jun 4, 2019
abfa197
cleaning code and dependencies
patzick Jun 7, 2019
ed6492f
Merge branch 'magento-catalog' of https://github.com/patzick/vue-stor…
patzick Jun 7, 2019
0549431
merge develop
patzick Jun 11, 2019
447130b
Merge branch 'develop' into magento-catalog
patzick Jun 13, 2019
6867930
linter errors
patzick Jun 14, 2019
c648c3c
correct getter
patzick Jun 14, 2019
e4665e0
default argument
patzick Jun 17, 2019
2e9e140
filter event
patzick Jun 17, 2019
541add0
Merge branch 'develop' into magento-catalog
patzick Jun 19, 2019
c908fdb
cleanup and add types to category service
patzick Jun 22, 2019
02f542a
linter and category interface
patzick Jun 22, 2019
07a52d1
categories as map
patzick Jun 22, 2019
9d6909e
add missing translation
patzick Jun 24, 2019
bce5a2d
cleanup
patzick Jun 24, 2019
d1ca817
recurrent breadcrumbs
patzick Jun 24, 2019
67087ea
mock configuration for configureProductAsync
patzick Jun 24, 2019
867f582
additional test to check buildProductsQuery
patzick Jun 24, 2019
37aca5e
categories hierarchy map and loading categories to breadcrumbs by one…
patzick Jun 24, 2019
64aeff6
Change caegoryFilters to object
patzick Jun 25, 2019
0fc7b6d
breadcrumbs from categories hierarchy map
patzick Jun 25, 2019
ba9f93b
do no t duplicate optionLabel helper
patzick Jun 25, 2019
94e5d23
composition function for proper SSR/CSR caching
patzick Jun 25, 2019
3da38c0
code cleanup
patzick Jun 25, 2019
35638d3
add default breadcrumb value
patzick Jun 25, 2019
7329923
improve filters reactivity on product page
patzick Jun 25, 2019
097eebb
fix problem with available options
patzick Jun 25, 2019
cfafe84
merge develop
patzick Jun 25, 2019
b868176
sorting filters
patzick Jun 25, 2019
dee2ead
lnter
patzick Jun 25, 2019
e345a04
Merge branch 'develop' into magento-catalog
patzick Jun 26, 2019
a0e993d
add infinite scroll pagination
patzick Jun 26, 2019
9659e6f
categoryHierarchyMap
patzick Jun 26, 2019
0f61390
Merge branch 'develop' into magento-catalog
patzick Jun 26, 2019
aa41c09
remove hierarchyMap - build from specific category
patzick Jun 27, 2019
8545d57
Fix problem with products caching on SSR
patzick Jun 27, 2019
52e8854
refactor category page getters names
patzick Jun 27, 2019
61ae322
Merge branch 'develop' into magento-catalog
patzick Jun 28, 2019
6153d69
remove unused hook
patzick Jun 28, 2019
779ce67
fix for product option values incomplete
patzick Jul 1, 2019
f31ac67
prefetch stock for cached products
patzick Jul 1, 2019
ddc3cde
Merge branch 'develop' into magento-catalog
patzick Jul 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
"setupVariantByAttributeCode": true,
"endpoint": "/api/product",
"defaultFilters": ["color", "size", "price", "erin_recommends"],
"routerFiltersSource": "query",
"filterFieldMapping": {
"category.name": "category.name.keyword"
},
Expand Down
8 changes: 5 additions & 3 deletions core/build/webpack.prod.sw.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ module.exports = merge(base, {
{
urlPattern: '/img/(.*)',
handler: 'fastest'
}, {
urlPattern: '/api/catalog/*',
},
{
urlPattern: /(http[s]?:\/\/)?(\/)?([^\/\s]+\/)?(api\/catalog\/)(.*)/g, // eslint-disable-line no-useless-escape
handler: 'networkFirst'
}, {
},
{
urlPattern: '/api/*',
handler: 'networkFirst'
}, {
Expand Down
2 changes: 1 addition & 1 deletion core/compatibility/components/blocks/Category/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
return this.getActiveCategoryFilters
},
availableFilters () {
return pickBy(this.filters, (filter) => { return (filter.length) })
return pickBy(this.filters, (filter, filterType) => { return (filter.length && !this.$store.getters['category-next/getSystemFilterNames'].includes(filterType)) })
},
hasActiveFilters () {
return Object.keys(this.activeFilters).length !== 0
Expand Down
48 changes: 48 additions & 0 deletions core/data-resolver/CategoryService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { quickSearchByQuery } from '@vue-storefront/core/lib/search';
import SearchQuery from '@vue-storefront/core/lib/search/searchQuery';
import config from 'config';
import { DataResolver } from './types/DataResolver';
import { Category } from 'core/modules/catalog-next/types/Category';

const getCategories = async ({
parentId = null,
filters = {},
level = null,
onlyActive = true,
onlyNotEmpty = false,
size = 4000,
start = 0,
sort = 'position:asc',
includeFields = config.entities.optimize ? config.entities.category.includeFields : null,
excludeFields = config.entities.optimize ? config.entities.category.excludeFields : null
}: DataResolver.CategorySearchOptions = {}): Promise<Category[]> => {
let searchQuery = new SearchQuery()
if (parentId) {
searchQuery = searchQuery.applyFilter({key: 'parent_id', value: {'eq': parentId}})
}
if (level) {
searchQuery = searchQuery.applyFilter({key: 'level', value: {'eq': level}})
}

for (var [key, value] of Object.entries(filters)) {
if (Array.isArray(value)) {
searchQuery = searchQuery.applyFilter({key: key, value: {'in': value}})
} else {
searchQuery = searchQuery.applyFilter({key: key, value: {'eq': value}})
}
}

if (onlyActive === true) {
searchQuery = searchQuery.applyFilter({key: 'is_active', value: {'eq': true}})
}

if (onlyNotEmpty === true) {
searchQuery = searchQuery.applyFilter({key: 'product_count', value: {'gt': 0}})
}
const response = await quickSearchByQuery({ entityType: 'category', query: searchQuery, sort: sort, size: size, start: start, includeFields: includeFields, excludeFields: excludeFields })
return response.items as Category[]
}

export const CategoryService: DataResolver.CategoryService = {
getCategories
}
5 changes: 5 additions & 0 deletions core/data-resolver/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CategoryService } from './CategoryService';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set sideEffects: false for this in package.json


export {
CategoryService
}
21 changes: 21 additions & 0 deletions core/data-resolver/types/DataResolver.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Category } from 'core/modules/catalog-next/types/Category';

declare namespace DataResolver {

interface CategorySearchOptions {
parentId?: number,
filters?: { [key: string]: string[] | string },
level?: number,
onlyActive?: boolean,
onlyNotEmpty?: boolean,
size?: number,
start?: number,
sort?: string,
includeFields?: string[],
excludeFields?: string[]
}

interface CategoryService {
getCategories: (searchRequest?: CategorySearchOptions) => Promise<Category[]>
}
}
23 changes: 13 additions & 10 deletions core/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,27 @@ export function baseFilterProductsQuery (parentCategory, filters = []) { // TODO
return searchProductQuery
}

export function buildFilterProductsQuery (currentCategory, chosenFilters, defaultFilters = null) {
export function buildFilterProductsQuery (currentCategory, chosenFilters = {}, defaultFilters = null) {
let filterQr = baseFilterProductsQuery(currentCategory, defaultFilters == null ? config.products.defaultFilters : defaultFilters)

// add choosedn filters
for (let code of Object.keys(chosenFilters)) {
const filter = chosenFilters[code]
const attributeCode = Array.isArray(filter) ? filter[0].attribute_code : filter.attribute_code

if (filter.attribute_code !== 'price') {
filterQr = filterQr.applyFilter({key: filter.attribute_code, value: {'eq': filter.id}, scope: 'catalog'})
if (Array.isArray(filter) && attributeCode !== 'price') {
const values = filter.map(filter => filter.id)
filterQr = filterQr.applyFilter({key: attributeCode, value: {'in': values}, scope: 'catalog'})
} else if (attributeCode !== 'price') {
filterQr = filterQr.applyFilter({key: attributeCode, value: {'eq': filter.id}, scope: 'catalog'})
} else { // multi should be possible filter here?
const rangeqr = {}
if (filter.from) {
rangeqr['gte'] = filter.from
}
if (filter.to) {
rangeqr['lte'] = filter.to
}
filterQr = filterQr.applyFilter({key: filter.attribute_code, value: rangeqr, scope: 'catalog'})
const filterValues = Array.isArray(filter) ? filter : [filter]
filterValues.forEach(singleFilter => {
if (singleFilter.from) rangeqr['gte'] = singleFilter.from
if (singleFilter.to) rangeqr['lte'] = singleFilter.to
})
filterQr = filterQr.applyFilter({key: attributeCode, value: rangeqr, scope: 'catalog'})
}
}

Expand Down
1 change: 1 addition & 0 deletions core/i18n/resource/i18n/en-US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
"Quantity must be above 0","Quantity must be above 0"
"Error: Error while adding products","Error: Error while adding products"
"Unexpected authorization error. Check your Network conection.","Unexpected authorization error. Check your Network conection."
"Columns","Columns"
"You are going to pay for this order upon delivery.","You are going to pay for this order upon delivery."
2 changes: 1 addition & 1 deletion core/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function isOnline (): boolean {
* @param {Int} size page size
* @return {Promise}
*/
export const quickSearchByQuery = async ({ query, start = 0, size = 50, entityType = 'product', sort = '', storeCode = null, excludeFields = null, includeFields = null }): Promise<SearchResponse> => {
export const quickSearchByQuery = async ({ query = {}, start = 0, size = 50, entityType = 'product', sort = '', storeCode = null, excludeFields = null, includeFields = null } = {}): Promise<SearchResponse> => {
const searchAdapter = await getSearchAdapter()
if (size <= 0) size = 50
if (start < 0) start = 0
Expand Down
16 changes: 16 additions & 0 deletions core/modules/catalog-next/helpers/categoryHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Category, ChildrenData } from '../types/Category';

export const compareByLabel = (a, b) => {
if (a.label < b.label) {
return -1
}
if (a.label > b.label) {
return 1
}
return 0
}

export const _prepareCategoryPathIds = (category: Category): string[] => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ indicates private fn yet you export it, why?

if (!category || !category.path) return []
return category.path.split('/')
}
54 changes: 54 additions & 0 deletions core/modules/catalog-next/helpers/filterHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import FilterVariant from 'core/modules/catalog-next/types/FilterVariant';

export const getSystemFilterNames: string[] = ['sort']

/**
* Creates new filtersQuery (based on currentQuery) by modifying specific filter variant.
*/
export const changeFilterQuery = ({currentQuery = {}, filterVariant}: {currentQuery?: any, filterVariant?: FilterVariant} = {}) => {
const newQuery = JSON.parse(JSON.stringify(currentQuery))
if (!filterVariant) return newQuery
if (getSystemFilterNames.includes(filterVariant.type)) {
if (newQuery[filterVariant.type] && newQuery[filterVariant.type] === filterVariant.id) {
delete newQuery[filterVariant.type]
} else {
newQuery[filterVariant.type] = filterVariant.id
}
} else {
let queryFilter = newQuery[filterVariant.type] || []
if (!Array.isArray(queryFilter)) queryFilter = [queryFilter]
if (queryFilter.includes(filterVariant.id)) {
queryFilter = queryFilter.filter(value => value !== filterVariant.id)
} else {
queryFilter.push(filterVariant.id)
}
newQuery[filterVariant.type] = queryFilter
}
return newQuery
}

export const getFiltersFromQuery = ({filtersQuery = {}, availableFilters = {}} = {}) => {
const searchQuery = {
filters: {}
}
Object.keys(filtersQuery).forEach(filterKey => {
const filter = availableFilters[filterKey]
const queryValue = filtersQuery[filterKey]
if (!filter) return
if (getSystemFilterNames.includes(filterKey)) {
searchQuery[filterKey] = queryValue
} else if (Array.isArray(queryValue)) {
queryValue.map(singleValue => {
const variant = filter.find(filterVariant => filterVariant.id === singleValue)
if (!variant) return
if (!searchQuery.filters[filterKey] || !Array.isArray(searchQuery.filters[filterKey])) searchQuery.filters[filterKey] = []
searchQuery.filters[filterKey].push({...variant, attribute_code: filterKey})
})
} else {
const variant = filter.find(filterVariant => filterVariant.id === queryValue)
if (!variant) return
searchQuery.filters[filterKey] = {...variant, attribute_code: filterKey}
}
})
return searchQuery
}
4 changes: 4 additions & 0 deletions core/modules/catalog-next/helpers/optionLabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { optionLabel } from '@vue-storefront/core/modules/catalog/helpers/optionLabel'

// TODO in future move old helper here, add tests and refactor
export { optionLabel }
10 changes: 10 additions & 0 deletions core/modules/catalog-next/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { categoryModule } from './store/category'
import { createModule } from '@vue-storefront/core/lib/module'

export const KEY = 'catalog-next'
export default createModule({
key: KEY,
store: { modules: [
{ key: 'category-next', module: categoryModule }
] }
})
9 changes: 9 additions & 0 deletions core/modules/catalog-next/store/category/CategoryState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Category } from '../../types/Category';
import Product from 'core/modules/catalog/types/Product';

export default interface CategoryState {
categoriesMap: { [id: string]: Category },
availableFilters: any,
products: Product[],
searchProductsStats: any
}
134 changes: 134 additions & 0 deletions core/modules/catalog-next/store/category/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// import Vue from 'vue'
import { ActionTree } from 'vuex'
import * as types from './mutation-types'
import RootState from '@vue-storefront/core/types/RootState'
import CategoryState from './CategoryState'
import { quickSearchByQuery } from '@vue-storefront/core/lib/search'
import { buildFilterProductsQuery } from '@vue-storefront/core/helpers'
import { router } from '@vue-storefront/core/app'
import FilterVariant from '../../types/FilterVariant'
import { CategoryService } from '@vue-storefront/core/data-resolver'
import { changeFilterQuery } from '../../helpers/filterHelpers'
import { products } from 'config'
import { configureProductAsync } from '@vue-storefront/core/modules/catalog/helpers'
import { DataResolver } from 'core/data-resolver/types/DataResolver';
import { Category } from '../../types/Category';
import { _prepareCategoryPathIds } from '../../helpers/categoryHelpers';
import chunk from 'lodash-es/chunk'

const actions: ActionTree<CategoryState, RootState> = {
async loadCategoryProducts ({ commit, getters, dispatch, rootState }, { route, category } = {}) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho products should be cached by default. No additional work should be required to do this

const searchCategory = category || getters.getCategoryFrom(route.path)
await dispatch('loadCategoryFilters', searchCategory)
const searchQuery = getters.getCurrentFiltersFrom(route[products.routerFiltersSource])
let filterQr = buildFilterProductsQuery(searchCategory, searchQuery.filters)
const {items, perPage, start, total} = await quickSearchByQuery({ query: filterQr, sort: searchQuery.sort })
commit(types.CATEGORY_SET_SEARCH_PRODUCTS_STATS, { perPage, start, total })
let configuredProducts = items.map(product => {
const configuredProductVariant = configureProductAsync({rootState, state: {current_configuration: {}}}, {product, configuration: searchQuery.filters, selectDefaultVariant: false, fallbackToDefaultWhenNoAvailable: true, setProductErorrs: false})
return Object.assign(product, configuredProductVariant)
})
commit(types.CATEGORY_SET_PRODUCTS, configuredProducts)
// await dispatch('loadAvailableFiltersFrom', searchResult)

return items
},
async loadMoreCategoryProducts ({ commit, getters, rootState }) {
const { perPage, start, total } = getters.getCategorySearchProductsStats
if (start >= total || total < perPage) return

const searchQuery = getters.getCurrentSearchQuery
let filterQr = buildFilterProductsQuery(getters.getCurrentCategory, searchQuery.filters)
const searchResult = await quickSearchByQuery({ query: filterQr, sort: searchQuery.sort, start: start + perPage, size: perPage })
commit(types.CATEGORY_SET_SEARCH_PRODUCTS_STATS, {
perPage: searchResult.perPage,
start: searchResult.start,
total: searchResult.total
})
let configuredProducts = searchResult.items.map(product => {
const configuredProductVariant = configureProductAsync({rootState, state: {current_configuration: {}}}, {product, configuration: searchQuery.filters, selectDefaultVariant: false, fallbackToDefaultWhenNoAvailable: true, setProductErorrs: false})
return Object.assign(product, configuredProductVariant)
})
commit(types.CATEGORY_ADD_PRODUCTS, configuredProducts)

return searchResult.items
},
async cacheProducts ({ commit, getters, dispatch, rootState }, { route } = {}) {
const searchCategory = getters.getCategoryFrom(route.path)
const searchQuery = getters.getCurrentFiltersFrom(route[products.routerFiltersSource])
let filterQr = buildFilterProductsQuery(searchCategory, searchQuery.filters)

const cachedProductsResponse = await dispatch('product/list', {
query: filterQr,
sort: searchQuery.sort,
updateState: false // not update the product listing - this request is only for caching
}, { root: true })
if (products.filterUnavailableVariants && products.configurableChildrenStockPrefetchStatic) { // prefetch the stock items
const skus = []
let prefetchIndex = 0
cachedProductsResponse.items.map(i => {
if (products.configurableChildrenStockPrefetchStaticPrefetchCount > 0) {
if (prefetchIndex > products.configurableChildrenStockPrefetchStaticPrefetchCount) return
}
skus.push(i.sku) // main product sku to be checked anyway
if (i.type_id === 'configurable' && i.configurable_children && i.configurable_children.length > 0) {
for (const confChild of i.configurable_children) {
const cachedItem = rootState.stock.cache[confChild.id]
if (typeof cachedItem === 'undefined' || cachedItem === null) {
skus.push(confChild.sku)
}
}
prefetchIndex++
}
})
for (const chunkItem of chunk(skus, 15)) {
dispatch('stock/list', { skus: chunkItem }, { root: true }) // store it in the cache
}
}
},
async findCategories (context, categorySearchOptions: DataResolver.CategorySearchOptions): Promise<Category[]> {
return CategoryService.getCategories(categorySearchOptions)
},
async loadCategories ({ commit }, categorySearchOptions: DataResolver.CategorySearchOptions): Promise<Category[]> {
const categories = await CategoryService.getCategories(categorySearchOptions)
commit(types.CATEGORY_ADD_CATEGORIES, categories)
return categories
},
async loadCategory ({ commit }, categorySearchOptions: DataResolver.CategorySearchOptions): Promise<Category> {
const categories: Category[] = await CategoryService.getCategories(categorySearchOptions)
const category: Category = categories && categories.length ? categories[0] : null
commit(types.CATEGORY_ADD_CATEGORY, category)
return category
},
/**
* Fetch and process filters from current category and sets them in available filters.
*/
async loadCategoryFilters ({ dispatch, getters }, category) {
const searchCategory = category || getters.getCurrentCategory
let filterQr = buildFilterProductsQuery(searchCategory)
const searchResult = await quickSearchByQuery({ query: filterQr })
await dispatch('loadAvailableFiltersFrom', searchResult)
},
async loadAvailableFiltersFrom ({ commit, getters }, {aggregations}) {
const filters = getters.getAvailableFiltersFrom(aggregations)
commit(types.CATEGORY_SET_AVAILABLE_FILTERS, filters)
},
async switchSearchFilter ({ dispatch }, filterVariant: FilterVariant) {
const newQuery = changeFilterQuery({currentQuery: router.currentRoute[products.routerFiltersSource], filterVariant})
await dispatch('changeRouterFilterParameters', newQuery)
},
async resetSearchFilters ({dispatch}) {
await dispatch('changeRouterFilterParameters', {})
},
async changeRouterFilterParameters (context, query) {
router.push({[products.routerFiltersSource]: query})
},
async loadCategoryBreadcrumbs ({ dispatch, getters }, category: Category) {
if (!category) return
const categoryHierarchyIds = _prepareCategoryPathIds(category) // getters.getCategoriesHierarchyMap.find(categoryMapping => categoryMapping.includes(category.id))
const categoryFilters = { 'id': categoryHierarchyIds }
await dispatch('loadCategories', {filters: categoryFilters})
}
}

export default actions
Loading