Developer forum

Forum » Development » Create product

Create product


Reply

Hi!

I'm using this code to create a product:

 Product p = Product.Create("A22222");

        p.Name = "AAA";

            p.Active = true;

            p.Number = b.ArticleNo;

            p.Shop = Shop.getShops("SHOP1").get_Item(0);

            p.Save();

But it doesn't show up in the list of products in the Ecom admin interface. What can be wrong?

Best regards,
Per Ljung
REAB Data AB


Replies

 
Reply

Hi Per, I have modified your code. It should work properly now.

           
Product p = new Product("");    //use empty string as productID. This way Ecom tries to load the product and populate default values. Instead of empty constructor.

            // manual setting of product ID is not good solution, because it's a part of product key field (ProductID, VariantID, LanguageID). Please use Number field for not unique values, or create a product field.

 

            p.Name = "AAA";

            p.Active = true;

            p.Number = "ArticleNo"; 

            p.DefaultShopID = Shop.getShops("SHOP1").get_Item(0).ID;    //set shop ID

            p.Language = Dynamicweb.eCommerce.Common.Application.DefaultLanguage;   //set language ID

            p.Groups.Add(new Group("GROUP1"));      // add product to a group.

            p.Save();

Kind regards.

 

You must be logged in to post in the forum