-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into feature/3249-ref…
…actoring-vuex-cart
- Loading branch information
Showing
13 changed files
with
273 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { products } from 'config' | ||
|
||
export const prefetchStockItems = (cachedProductsResponse, cache = {}) => { | ||
const skus = [] | ||
let prefetchIndex = 0 | ||
cachedProductsResponse.items.map(i => { | ||
if (products.configurableChildrenStockPrefetchStatic && | ||
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 = cache[confChild.id] | ||
if (typeof cachedItem === 'undefined' || cachedItem === null) { | ||
skus.push(confChild.sku) | ||
} | ||
} | ||
prefetchIndex++ | ||
} | ||
}) | ||
|
||
return skus | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
core/modules/catalog-next/test/unit/prefetchStockItems.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import {prefetchStockItems} from '../../helpers/cacheProductsHelper'; | ||
import config from 'config'; | ||
|
||
describe('prefetchStockItems method', () => { | ||
describe('default configurableChildrenStockPrefetchStaticPrefetchCount', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.mock('config', () => ({})); | ||
}) | ||
|
||
it('returns an empty array when no items are provided', () => { | ||
const cachedProductsResponse = { | ||
items: [] | ||
} | ||
const result = prefetchStockItems(cachedProductsResponse) | ||
expect(result).toEqual([]); | ||
}) | ||
|
||
it('returns the skus of the children of a configurable', () => { | ||
const cachedProductsResponse = { | ||
items: [ | ||
{sku: 'foo'}, | ||
{ | ||
sku: 'bar', | ||
type_id: 'configurable', | ||
configurable_children: [ | ||
{sku: 'bar.foo'}, | ||
{sku: 'bar.bar'}, | ||
{sku: 'bar.baz'} | ||
] | ||
}, | ||
{sku: 'baz'} | ||
] | ||
} | ||
const result = prefetchStockItems(cachedProductsResponse) | ||
expect(result).toEqual(['foo', 'bar', 'bar.foo', 'bar.bar', 'bar.baz', 'baz']); | ||
}) | ||
|
||
it('returns the same skus of the provided simple products', () => { | ||
const cachedProductsResponse = { | ||
items: [ | ||
{sku: 'foo'}, | ||
{sku: 'bar'}, | ||
{sku: 'baz'} | ||
] | ||
} | ||
const result = prefetchStockItems(cachedProductsResponse) | ||
expect(result).toEqual(['foo', 'bar', 'baz']); | ||
}) | ||
|
||
it('ignores the pre-cached skus of children of a configurable', () => { | ||
const cachedProductsResponse = { | ||
items: [ | ||
{sku: 'foo'}, | ||
{ | ||
sku: 'bar', | ||
type_id: 'configurable', | ||
configurable_children: [ | ||
{sku: 'bar.foo', id: 1337}, | ||
{sku: 'bar.bar'}, | ||
{sku: 'bar.baz', id: 4711} | ||
] | ||
}, | ||
{sku: 'baz'} | ||
] | ||
} | ||
const result = prefetchStockItems(cachedProductsResponse, {1337: {}, 4711: {}}) | ||
expect(result).toEqual(['foo', 'bar', 'bar.bar', 'baz']); | ||
}) | ||
}) | ||
}) |
38 changes: 38 additions & 0 deletions
38
core/modules/catalog/helpers/areAttributesAlreadyLoaded.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import config from 'config' | ||
|
||
const areAttributesAlreadyLoaded = ({ | ||
filterValues, | ||
filterField, | ||
blacklist, | ||
idsList, | ||
codesList | ||
}: { | ||
filterValues: string[], | ||
filterField: string, | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import SearchQuery from '@vue-storefront/core/lib/search/searchQuery' | ||
|
||
const createAttributesListQuery = ({ | ||
filterValues, | ||
filterField, | ||
onlyDefinedByUser, | ||
onlyVisible | ||
}: { | ||
filterValues: string[], | ||
filterField: string, | ||
onlyDefinedByUser: boolean, | ||
onlyVisible: boolean | ||
}): SearchQuery => { | ||
let searchQuery = new SearchQuery() | ||
|
||
if (filterValues) { | ||
searchQuery = searchQuery.applyFilter({key: filterField, value: {'in': filterValues}}) | ||
} | ||
if (onlyDefinedByUser) { | ||
searchQuery = searchQuery.applyFilter({key: 'is_user_defined', value: {'in': [true]}}) | ||
} | ||
if (onlyVisible) { | ||
searchQuery = searchQuery.applyFilter({key: 'is_visible', value: {'in': [true]}}) | ||
} | ||
|
||
return searchQuery | ||
} | ||
|
||
export default createAttributesListQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Attribute from '@vue-storefront/core/modules/catalog/types/Attribute' | ||
|
||
const reduceAttributes = (prev, curr) => { | ||
if (curr) { | ||
prev.attrHashByCode[curr.attribute_code] = curr | ||
prev.attrHashById[curr.attribute_id] = curr | ||
} | ||
|
||
return prev | ||
} | ||
|
||
const reduceAttributesLists = ({ | ||
codesList, | ||
idsList, | ||
attributes | ||
}: { | ||
codesList: any, | ||
idsList: any, | ||
attributes: Attribute[] | ||
}) => { | ||
return attributes.reduce( | ||
reduceAttributes, { attrHashByCode: codesList, attrHashById: idsList } | ||
) | ||
} | ||
|
||
export default reduceAttributesLists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const SN_ATTRIBUTE = 'attribute' | ||
export const ATTRIBUTE_UPD_ATTRIBUTES = SN_ATTRIBUTE + '/UPD_ATTRIBUTES' | ||
export const ATTRIBUTE_UPD_BLACKLIST = SN_ATTRIBUTE + '/UPD_BLACKLIST_ATTRIBUTES' |
Oops, something went wrong.