My scenario: I have NOPCommerce set on a cloth store, so for each t-shirt I need to create variant attribute values for size (S,M,L,XL) every time one by one.
So I found a quick way to just click a button to add them.
I modified the ProductVariantAttributesControl.ascx adding at the bottom a dropdownlist with my common sizes:
Predifined Size Attribute Values:
<asp:DropDownList runat="server" ID="ddlPredifinedSizes">
<asp:ListItem Value="S,M,L,XL,XXL">S,M,L,XL,XXL</asp:ListItem>
<asp:ListItem Value="S,M,L,XL">S,M,L,XL</asp:ListItem>
<asp:ListItem Value="S,M,L">S,M,L</asp:ListItem>
</asp:DropDownList>
<asp:Button runat="server" ID="btnPredifinedSizes" Text="Add" onclick="btnPredifinedSizes_Click" />
And the code:
protected void btnPredifinedSizes_Click(object sender, EventArgs e)
{
try
{
ProductVariant productVariant = ProductManager.GetProductVariantByID(this.ProductVariantID);
if (productVariant != null)
{
//Add Attribute -------------------
int productAttributeID = 1; //Your Attribute ID
AttributeControlTypeEnum attributeControlType = (AttributeControlTypeEnum)Enum.ToObject(typeof(AttributeControlTypeEnum), int.Parse("1")); //Type of Dropdownlist
ProductVariantAttribute productVariantAttribute = ProductAttributeManager.InsertProductVariantAttribute(productVariant.ProductVariantID, productAttributeID, true, attributeControlType, 1);
//Add Attribute Values ------------
if (productVariantAttribute != null)
{
String[] arrSizes = ddlPredifinedSizes.SelectedValue.Split(",".ToCharArray());
int x = 1;
foreach (String s in arrSizes)
{
ProductAttributeManager.InsertProductVariantAttributeValue(productVariantAttribute.ProductVariantAttributeID, s, 0, 0, false, x);
x++;
}
}
BindData();
}
}
catch (Exception exc)
{
ProcessException(exc);
}
}
Hopefuly in a future version of NOP this will be supported.
Damiano