Ecommerce application needs product updates daily or frequently to show up to latest products information on their website. Sometimes the product information gets from company business users and sometimes the products information comes from vendors. For large scale ecommerce application, middleware servers like BizTalk are used for product import.

This current tool (attached to this article) is command based tool and be perfect for small companies with limited data upload and can be used only one time (during application migration) or regularly. This tools takes catalog data using excel file and through commerce server API, it inserts data into database.

The excel file template contains three sheets.

1.    First sheet name  is “CategoryData” – This sheet contains categories details.
2.    Second sheet name is “ProductData” – This sheet contains product details.
3.     Third Sheet name is “VariantData” – This sheet contains variant data.

Note: Kindly don’t change sheet names.

When the tool is executed, it will ask for data excel file path. Once correct path is provided, it will ask whether to import category data, product data or variant data. Based on the option selected, the tool starts porting data into commerce server.

The assumption is that the given catalog and product definition are created in commerce server.

How to add a category?

Category can be created under a Catalog only. So, before we create category, the application should get context of Catalog, then by using method CreateCategory(), category can be created.

BaseCatalog baseCatalog = (BaseCatalog)context.GetCatalog((string)row["CatalogName"]);
Category category = baseCatalog.CreateCategory((string)row["CategoryDefinition"], (string)row["CategoryName"]);
category.DisplayName = (string)row["DisplayName"];
category.Save();

How to add a Product?

Product can be created under catalog or category. So before we create product, the application should get catalog context. By using CreateProduct(), a product can be created. If the products need to be created under a category, then pass category information to CreateProduct() method.

BaseCatalog baseCatalog = (BaseCatalog)context.GetCatalog((string)row["CatalogName"]);
Product product = baseCatalog.CreateProduct((string)row["ProductDefinition"], (string)row["ProductID"], Convert.ToDecimal(row["ListPrice"]), (string)row["CategoryName"]);
product.DisplayName = (string)row["DisplayName"];
product["Image"] = row["Image"];
product["Description"] = row["Description"];
product.Save();

How to add a variant?

Products may or may not have a variant. For example, a shoe can have multiple variants like size, color, etc and some products don’t have variants like Books. To create a variant, the application should get product definition and to get product definition, the application needs to get catalog context. Once product definition obtained, we can add a new variant using AddVariant() method as shown below.

BaseCatalog baseCatalog = (BaseCatalog)context.GetCatalog((string)row["CatalogName"]);
ProductFamily productFamily = (ProductFamily)baseCatalog.GetProduct((string)row["ProductID"]);string variantID = (string)row["VariantID"];
// Add the variant to the product family.
productFamily.AddVariant(variantID);
// Set the properties for the variant product. 
productFamily.Variants[variantID]["VariantActualPrice"] = Convert.ToDecimal(row["VariantListPrice"]);
productFamily.Variants[variantID]["Color"] = (string)row["VariantColor"];
productFamily.Variants[variantID]["Size"] = (string)row["VariantSize"]
productFamily.Variants[variantID]["VariantDisplayName"] = (string)row["VariantDisplayName"];
productFamily.Save();

If you have any questions/suggestions on his approach, feel free to send your comments. Click here to download Catalog Importer.

Related Articles


If you like this post, please click on our sponsor advertisement.


8 Responses to “Catalog Importer”

  • Ralf Hoeppner:

    Hey Ravi,

    thanks for sharing that with us! – This is exatly what I was looking for…

    best,
    Ralf

  • [...] years back, I have blogged catalog importer, which will help us to import catalog data into commerce server. I have used this tool in many [...]

  • Hi Ravi,
    Thanks for sharing the tool.
    I would like to extend the tool and add few more features to it.
    Kindly let me know if I may extend and publish the Importer. Of course I will be sharing the Source code and Credits in the blog post.

    Regards
    Rajendra Dewani

  • raga:

    I am now facing an issue with the Product Query Webpart. We have migrated all Variants from Catalog API through Visual studio. When i try to include Variants(Checkbox in Product Provider webpart) its throwing an error like Product provider webpart cannot be diaplayed. An error occured. If i add the Variants across a product through Catalog manager across a product, its working fine. Can you please let me know if there is any solution or Fix?

    • I saw your email reply.. hope your issue is fixed permanently.

      For the others, there was a Mismatch in Product definition name. The Variants and Products created manually were taking the Actual case of product Definition name as per the API where as the Catalog that was imported was having lower case of the Product Definition Name. Since CS catalog system is case sensitive, the users is getting this exception.

  • Bhushan:

    Hi Ravi,
    Thanks for Sharing this valuable tool
    how do you manage the Parent and Child Category Hierarchies in the Excel?
    is there specific format in which we should fill that data ?

Leave a Reply

Follow me on Google+
Couldn't get data from google+
Sign up for Newsletter