Skip to content

Commit

Permalink
Fixed disabled options when no options are available (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobWez98 authored Apr 16, 2024
1 parent b2b2510 commit 562217a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions resources/js/components/Product/AddToCart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,16 @@ export default {
Object.entries(this.product.super_attributes).forEach(([attributeId, attribute]) => {
disabledOptions['super_' + attribute.code] = []
valuesPerAttribute[attributeId] = {}
// Fill list with products per attribute value
Object.entries(this.product.children).forEach(([productId, option]) => {
if (!option.in_stock) {
return
}
if (!valuesPerAttribute[attributeId][option[attribute.code]]) {
valuesPerAttribute[attributeId][option[attribute.code]] = []
}
if (!option.in_stock) {
return
}
valuesPerAttribute[attributeId][option[attribute.code]].push(productId)
})
})
Expand All @@ -297,17 +296,22 @@ export default {
Object.entries(valuesPerAttribute).forEach(([attributeId2, productsPerValue2]) => {
if (attributeId === attributeId2) return
var selectedValueId = this.options[attributeId]
if (!selectedValueId) return
var attributeCode = this.product.super_attributes[attributeId2].code
Object.entries(productsPerValue2).forEach(([valueId, products]) => {
// If there is no product that intersects for this attribute value
// there will be no product available for this attribute value
if (!productsPerValue[selectedValueId] || productsPerValue[selectedValueId].some((val) => products.includes(val))) {
if (
products.length &&
(!selectedValueId ||
!productsPerValue[selectedValueId] ||
productsPerValue[selectedValueId].some((val) => products.includes(val)))
) {
return
}
disabledOptions['super_' + attributeCode].push(valueId)
disabledOptions['super_' + attributeCode].push(parseInt(valueId))
})
})
})
Expand Down

0 comments on commit 562217a

Please sign in to comment.