After adding an attribute of type Custom HTML text, if another attribute of Option type is then added to the product the CustomValue text from the previously added attribute is also written to the CustomValue column of the second attribute mapping.
Steps to replicate
1. Go to the product edit page and add a specification attribute to type Custom HTML text to the product
2. Change the attribute type dropdown to Option (without first clearing the text in the Custom Value field)
3. Add a second attribute of the Option type to the product.
4. Run a query against the database to find attribute mappings in the Product_SpecificationAttribute_Mapping table that have an AttributeTypeId = 0 and CustomValue <> ''
(I'd post the SQL for this but Cloudflare keeps blocking it as part of their security protection)
Under normal circumstances you wouldn't expect that query to return any results since the CustomValue column shouldn't apply to Option attributes but I'm seeing a lot of results in my database where option values have been added after custom html text values. This will also happen if the first attribute was custom text or hyperlink attribute type too.
I think this could be fixed in one of two ways:
1. Check the AttributeTypeId in the ProductSpecificationAttributeAdd ActionResult of the Administration ProductController.cs and set the CustomValue to an empty string if it's 0. e.g.
(addition in bold)
//we allow filtering only for "Option" attribute type
if (attributeTypeId != (int)SpecificationAttributeType.Option)
{
allowFiltering = false;
}
//we don't allow CustomValue for "Option" attribute type
if (attributeTypeId == (int)SpecificationAttributeType.Option)
{
customValue = string.Empty;
}
var psa = new ProductSpecificationAttribute
{
AttributeTypeId = attributeTypeId,
SpecificationAttributeOptionId = specificationAttributeOptionId,
ProductId = productId,
CustomValue = customValue,
AllowFiltering = allowFiltering,
ShowOnProductPage = showOnProductPage,
DisplayOrder = displayOrder,
};
2. In the toggleAttributeType() function of the _CreateOrUpdate.SpecificationAttributes.cshtml view make sure the contents of the CustomValue field are blanked when changing to to the Option AttributeType. e.g.
(addition in bold)
function toggleAttributeType() {
var selectedTypeId = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.AttributeTypeId)").val();
if (selectedTypeId == @(((int)SpecificationAttributeType.Option).ToString())) {
$('#pnlSpecificationAttributeOptionId').show();
$('#pnlCustomValue').hide();
$('#pnlAllowFiltering').show();
$("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.CustomValue)").val("");
} else if (selectedTypeId == @(((int)SpecificationAttributeType.CustomText).ToString())) {
$('#pnlSpecificationAttributeOptionId').hide();
$('#pnlCustomValue').show();
$('#pnlAllowFiltering').hide();
} else if (selectedTypeId == @(((int)SpecificationAttributeType.CustomHtmlText).ToString())) {
$('#pnlSpecificationAttributeOptionId').hide();
$('#pnlCustomValue').show();
$('#pnlAllowFiltering').hide();
} else if (selectedTypeId == @(((int)SpecificationAttributeType.Hyperlink).ToString())) {
$('#pnlSpecificationAttributeOptionId').hide();
$('#pnlCustomValue').show();
$('#pnlAllowFiltering').hide();
}
}
Hope that makes sense.
P.S. It would be great if had some sort of highlight option on the forum post wysiwyg editor. The bold text doesn't make the changes very obvious in a code block. Even just changing the css to change the text colour or background colour of bolded text would be enough.