Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- CookieNotification CSR&SSR mismatch fixed - @Fifciu (#3922)

- The attribute filter in `attribute/list` was not filtering the already loaded attributes properly - @pkarw (#3964)

## [1.11.0] - 2019.12.20

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from 'config'

const areAttributesAlreadyLoaded = ({
export default function filterAttributes ({
filterValues,
filterField,
blacklist,
Expand All @@ -12,27 +12,22 @@ const areAttributesAlreadyLoaded = ({
blacklist: string[],
idsList: any,
codesList: any
}): boolean => {
}) {
return filterValues.filter(fv => {
if (config.entities.product.standardSystemFields.indexOf(fv) >= 0) {
return false
}

if (fv.indexOf('.') >= 0) {
return false
}

if (blacklist !== null && blacklist.includes(fv)) {
return false
}

if (filterField === 'attribute_id') {
return (typeof idsList[fv] === 'undefined' || idsList[fv] === null)
}
if (filterField === 'attribute_code') {
return (typeof codesList[fv] === 'undefined' || codesList[fv] === null)
}
}).length === 0
})
}

export default areAttributesAlreadyLoaded
5 changes: 3 additions & 2 deletions core/modules/catalog/store/attribute/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import config from 'config'
import { Logger } from '@vue-storefront/core/lib/logger'
import { entityKeyName } from '@vue-storefront/core/lib/store/entities'
import { prefetchCachedAttributes } from '../../helpers/prefetchCachedAttributes'
import areAttributesAlreadyLoaded from './../../helpers/areAttributesAlreadyLoaded'
import createAttributesListQuery from './../../helpers/createAttributesListQuery'
import reduceAttributesLists from './../../helpers/reduceAttributesLists'
import filterAttributes from '../../helpers/filterAttributes'

const actions: ActionTree<AttributeState, RootState> = {
async updateAttributes ({ commit, getters }, { attributes }) {
Expand Down Expand Up @@ -63,7 +63,8 @@ const actions: ActionTree<AttributeState, RootState> = {

await dispatch('loadCachedAttributes', { filterField, filterValues })

if (areAttributesAlreadyLoaded({ filterValues, filterField, blacklist, idsList, codesList })) {
filterValues = filterAttributes({ filterValues, filterField, blacklist, idsList, codesList })
if (filterValues.length === 0) {
Logger.info('Skipping attribute load - attributes already loaded', 'attr', { orgFilterValues, filterField })()
return { items: Object.values(codesList) }
}
Expand Down