diff --git a/CHANGELOG.md b/CHANGELOG.md index 499d7b431f..563a2c0be4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/core/modules/catalog/helpers/areAttributesAlreadyLoaded.ts b/core/modules/catalog/helpers/filterAttributes.ts similarity index 86% rename from core/modules/catalog/helpers/areAttributesAlreadyLoaded.ts rename to core/modules/catalog/helpers/filterAttributes.ts index 967578df43..fed1e51e57 100644 --- a/core/modules/catalog/helpers/areAttributesAlreadyLoaded.ts +++ b/core/modules/catalog/helpers/filterAttributes.ts @@ -1,6 +1,6 @@ import config from 'config' -const areAttributesAlreadyLoaded = ({ +export default function filterAttributes ({ filterValues, filterField, blacklist, @@ -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 diff --git a/core/modules/catalog/store/attribute/actions.ts b/core/modules/catalog/store/attribute/actions.ts index 260fa14e4b..38a9aed071 100644 --- a/core/modules/catalog/store/attribute/actions.ts +++ b/core/modules/catalog/store/attribute/actions.ts @@ -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 = { async updateAttributes ({ commit, getters }, { attributes }) { @@ -63,7 +63,8 @@ const actions: ActionTree = { 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) } }