Skip to content

Commit

Permalink
Merge pull request #2384 from pkarw/develop
Browse files Browse the repository at this point in the history
Configurable options attr. descriptor fix
  • Loading branch information
pkarw authored Feb 6, 2019
2 parents 21c062d + 18994c1 commit e8c4ab0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
29 changes: 14 additions & 15 deletions core/modules/catalog/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,21 @@ export function populateProductConfigurationAsync (context, { product, selectedV
for (let option of product.configurable_options) {
let attribute_code
let attribute_label
if (option.attribute_id) {
let attr = context.rootState.attribute.list_by_id[option.attribute_id]
if (!attr) {
Logger.error('Wrong attribute given in configurable_options - can not find by attribute_id', option)()
continue
} else {
attribute_code = attr.attribute_code
attribute_label = attr.frontend_label ? attr.frontend_label : attr.default_frontend_label
}
if (option.attribute_code) {
attribute_code = option.attribute_code
attribute_label = option.label ? option.label : (option.frontend_label ? option.frontend_label : option.default_frontend_label)
} else {
if (!option.attribute_code) {
Logger.error('Wrong attribute given in configurable_options - no attribute_code', option)()
continue
} else { // we do have attribute_code!
attribute_code = option.attribute_code
attribute_label = option.frontend_label ? option.frontend_label : option.default_frontend_label
if (option.attribute_id) {
let attr = context.rootState.attribute.list_by_id[option.attribute_id]
if (!attr) {
Logger.error('Wrong attribute given in configurable_options - can not find by attribute_id', option)()
continue
} else {
attribute_code = attr.attribute_code
attribute_label = attr.frontend_label ? attr.frontend_label : attr.default_frontend_label
}
} else {
Logger.error('Wrong attribute given in configurable_options - no attribute_code / attribute_id', option)()
}
}
let selectedOption = null
Expand Down
39 changes: 24 additions & 15 deletions core/modules/catalog/store/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,29 +214,37 @@ const actions: ActionTree<ProductState, RootState> = {
})
}
},
/**
* Load required configurable attributes
* @param context
* @param product
*/
loadConfigurableAttributes(context, { product }) {
let attributeKey = 'attribute_id'
const configurableAttrKeys = product.configurable_options.map(opt => {
if (opt.attribute_id) {
attributeKey = 'attribute_id'
return opt.attribute_id
} else {
attributeKey = 'attribute_code'
return opt.attribute_code
}
})
return context.dispatch('attribute/list', {
filterValues: configurableAttrKeys,
filterField: attributeKey
}, { root: true })
},
/**
* Setup product current variants
*/
setupVariants (context, { product }) {
let subloaders = []
if (product.type_id === 'configurable' && product.hasOwnProperty('configurable_options')) {
let attributeKey = 'attribute_id'
const configurableAttrKeys = product.configurable_options.map(opt => {
if (opt.attribute_id) {
attributeKey = 'attribute_id'
return opt.attribute_id
} else {
attributeKey = 'attribute_code'
return opt.attribute_code
}
})
subloaders.push(context.dispatch('attribute/list', {
filterValues: configurableAttrKeys,
filterField: attributeKey
}, { root: true }).then((attributes) => {

subloaders.push(context.dispatch('product/loadConfigurableAttributes', { product }, { root: true }).then((attributes) => {
context.state.current_options = {
}

for (let option of product.configurable_options) {
for (let ov of option.values) {
let lb = ov.label ? ov.label : optionLabel(context.rootState.attribute, { attributeKey: option.attribute_id, searchBy: 'id', optionId: ov.value_index })
Expand Down Expand Up @@ -568,6 +576,7 @@ const actions: ActionTree<ProductState, RootState> = {
context.commit(types.CATALOG_UPD_GALLERY, attributeImages(productVariant))
}
context.commit(types.CATALOG_SET_PRODUCT_CURRENT, productUpdated)
return productUpdated
} else Logger.debug('Unable to update current product.', 'product')()
},
/**
Expand Down

0 comments on commit e8c4ab0

Please sign in to comment.