Skip to content

Commit

Permalink
Merge pull request #2137 from pkarw/develop
Browse files Browse the repository at this point in the history
 Backward compatibility option for dynamic attribute loader
  • Loading branch information
pkarw authored Jan 8, 2019
2 parents 1067ea7 + e906367 commit 9ec6911
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"product": {
"excludeFields": [ "*.msrp_display_actual_price_type", "required_options", "updated_at", "created_at", "attribute_set_id", "options_container", "msrp_display_actual_price_type", "has_options", "stock.manage_stock", "stock.use_config_min_qty", "stock.use_config_notify_stock_qty", "stock.stock_id", "stock.use_config_backorders", "stock.use_config_enable_qty_inc", "stock.enable_qty_increments", "stock.use_config_manage_stock", "stock.use_config_min_sale_qty", "stock.notify_stock_qty", "stock.use_config_max_sale_qty", "stock.use_config_max_sale_qty", "stock.qty_increments", "small_image", "sgn", "*.sgn"],
"includeFields": null,
"useDynamicAttributeLoader": true,
"standardSystemFields": [
"description",
"configurable_options",
Expand Down
24 changes: 13 additions & 11 deletions core/modules/catalog/store/attribute/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ const actions: ActionTree<AttributeState, RootState> = {

let searchQuery = new SearchQuery()

const orgFilterValues = Object.assign({}, filterValues)
filterValues = filterValues.filter(fv => { // check the already loaded
if (filterField === 'attribute_id') return (typeof context.state.list_by_id[fv] === 'undefined' || context.state.list_by_id[fv] === null)
if (filterField === 'attribute_code') return (typeof context.state.list_by_code[fv] === 'undefined' || context.state.list_by_code[fv] === null)
return true
})
if (!filterValues || filterValues.length === 0) {
Logger.info('Skipping attribute load - attributes already loaded', 'attr', { orgFilterValues, filterField})()
return Promise.resolve({
items: Object.values(context.state.list_by_code)
if (filterValues) {
const orgFilterValues = Object.assign({}, filterValues)
filterValues = filterValues.filter(fv => { // check the already loaded
if (filterField === 'attribute_id') return (typeof context.state.list_by_id[fv] === 'undefined' || context.state.list_by_id[fv] === null)
if (filterField === 'attribute_code') return (typeof context.state.list_by_code[fv] === 'undefined' || context.state.list_by_code[fv] === null)
return true
})
if (!filterValues || filterValues.length === 0) {
Logger.info('Skipping attribute load - attributes already loaded', 'attr', { orgFilterValues, filterField})()
return Promise.resolve({
items: Object.values(context.state.list_by_code)
})
}
searchQuery = searchQuery.applyFilter({key: filterField, value: {'in': filterValues}})
}
searchQuery = searchQuery.applyFilter({key: filterField, value: {'in': filterValues}})
if (only_user_defined) {
searchQuery = searchQuery.applyFilter({key: 'is_user_defined', value: {'in': [true]}})
}
Expand Down
4 changes: 2 additions & 2 deletions core/modules/catalog/store/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ const actions: ActionTree<ProductState, RootState> = {
return rootStore.state.config.entities.product.standardSystemFields.indexOf(fieldName) < 0 // don't load metadata info for standard fields
})
subloaders.push(context.dispatch('attribute/list', { // load attributes to be shown on the product details - the request is now async
filterValues: productFields,
only_visible: true,
filterValues: rootStore.state.config.entities.product.useDynamicAttributeLoader ? productFields : null,
only_visible: rootStore.state.config.entities.product.useDynamicAttributeLoader ? true : false,
only_user_defined: true,
includeFields: rootStore.state.config.entities.optimize ? rootStore.state.config.entities.attribute.includeFields : null
}, { root: true }))
Expand Down

0 comments on commit 9ec6911

Please sign in to comment.