Pre-Defined Variant Attribute Values (like S,M,L,XL)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 лет назад
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
14 лет назад
I have been working on this for two weeks now...Your code does not work and I cant get anything eles working eather. This sucks cause I have 100 values to put in for each product. and nearly 30 items that have these.
14 лет назад
Hi,

This feature will be comming in NopCommerce.

For now the code provided will work.

What you need todo is go to NopCommerceStore/Administration/Modules/ProductVariantAttributes.ascx

Then Drop the DropDownList and Button on the page, Then,

go to NopCommerceStore/Administration/Modules/ProductVariantAttributes.ascx.cs

and make sure you have set up a attribute and call it size.

Take a note of the attribute ID by looking in the database at nop_ProductAtrribute.

Then paste the code behind inpreviously posted and change:


//Add Attribute -------------------
int productAttributeID = THE ATTRIBUTE ID; //Your Attribute ID


Hope this makes it a bit clearer for you.

mike..
14 лет назад
I have been working on this all day. I have followed both of your directions to the letter but still no joy. Do you know when this will be implimented into nopcommerce?
Thanks
Marc
14 лет назад
The code is pretty simple. What part does't work for you?
14 лет назад
To be honest I'm not sure. I don't have a server running on my machine just on the godaddy servers. I tried it meny diffrent ways at first then today I just cut and pasted. The only other thing I changed was "int productAttributeID = 13;" which doesnt go to "size" but looking at the code that really doesnt matter...it does point to an existing varent. I also had to cut part of the button line "onclick="btnPredifinedSizes_Click" because it kept poping an error. So I double clicked the button and entered the code in /ProductVariantAttributes.ascx.cs. If you could email me at marc[at]dooleyfam[dot]com I would really apreciate it. I am more of a vb.net winforms programmer than c# or asp.net but they are close enough that I shouldn't be having this much trouble.
thanks
M
13 лет назад
It looks like since the code above has code that'll go into the .cs file it looks like you'll need to re-build the solution for it to fully work. Once you've done that you should be good to go.
13 лет назад
Well, yes, brenjt is right. We all assumed that after changing the .cs file you need to compile and upload the dll file to the server. Perhaps that's why it didn't work for some people. I think this feature is not standard yet in nopCommerce.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.