a.m. wrote:Andri,
I think there is an important feature that is missing in NOP when using the attribute combination. I have notice that many NOPs were/are asking about this and i was one of them. The feature is to filter the attribute based on the customer selection of one of them. For example, if I have Colors & Sizes, when the customer select the RED color, the only the available sizes where the stock quantity is > 0 should be enabled for selection, others should be disabled. I was able to solve this by changing 2 files (_ProductAttributes.cshtml & ShoppingCartController.cs - ProductDetails_AttributeChange method).
I can share with you the code that i changed. I am sure you can support such feature easily and hope to see this on 3.90.
Sure, please share it
I have added these lines in the ProductDetails_AttributeChange method
//////////////////////////
List<string> disabledElements = new List<string>();
IList<ProductAttributeValue> selectedAttributeValues = _productAttributeParser.ParseProductAttributeValues(attributeXml);
// get the selected color
ProductAttributeValue selectedColor = selectedAttributeValues.Where(a => a.ProductAttributeMapping.ProductAttribute.Name.ToLower() == "color").SingleOrDefault();
if (selectedColor != null)
{
// Get the combinations
IList<ProductAttributeCombination> combinations = _productAttributeService.GetAllProductAttributeCombinations(product.Id);
foreach (ProductAttributeCombination item in combinations)
{
// Check the color
if (item.StockQuantity == 0)
{
IList<ProductAttributeValue> attributeValues = _productAttributeParser.ParseProductAttributeValues(item.AttributesXml);
// Check if the combination has the selected color attribute value
ProductAttributeValue ProductAttributeValue = attributeValues.Where(a => a.Id == selectedColor.Id).SingleOrDefault();
if (ProductAttributeValue != null)
{
// Disable the size
ProductAttributeValue sizeAttributeValue = attributeValues.Where(a => a.ProductAttributeMapping.ProductAttribute.Name.ToLower() == "size").SingleOrDefault();
if (sizeAttributeValue != null)
{
string elementId = "#li_product_attribute_" + sizeAttributeValue.ProductAttributeMappingId + "_" + sizeAttributeValue.Id;
disabledElements.Add(elementId);
}
}
}
}
}
// Update the bellow by adding disabledElementsids = disabledElements.ToArray()
return Json(new
{
gtin = gtin,
mpn = mpn,
sku = sku,
price = price,
stockAvailability = stockAvailability,
enabledattributemappingids = enabledAttributeMappingIds.ToArray(),
disabledattributemappingids = disabledAttributeMappingIds.ToArray(),
pictureFullSizeUrl = pictureFullSizeUrl,
pictureDefaultSizeUrl = pictureDefaultSizeUrl,
disabledElementsids = disabledElements.ToArray()
});
/////////////////////////////
in the _ProductAttributes.cshtml file, i did the following:
1- in the case AttributeControlType.RadioList, i update the li tag to be <li id="li_@(controlId)_@(attributeValue.Id)">
2- Before the last line $.event.trigger({ type: "product_attributes_changed", changedData: data }); i added the following:
$('.option-list').find('li').show();
if (data.disabledElementsids) {
for (var i = 0; i < data.disabledElementsids.length; i++) {
$(data.disabledElementsids[i]).hide();
}
}