Hide menu Last updated: Oct 12 2015

This topic explains options for importing catalog data between e-commerce sites, including the addition of metadata in multiple languages.

Classes in this topic are in the following namespaces:

Note: You should not import data directly into the catalog system database unless you have a full understanding of how it works.


Import scenarios and options

You can import catalog data

  • use the catalog export/import tool (XML or .csv files) available from the Commerce Manager user interface.
  • use the Episerver Service API to import the catalog XML.
  • write custom import code that uses the API. 

Catalog data from another Episerver Commerce site to your Episerver Commerce site

If you are moving a catalog from another Episerver Commerce site to your Episerver Commerce site, a catalog import and export feature uses XML to make this task straightforward.

Catalog data from a non-Episerver Commerce site to your Episerver Commerce site

Option 1: CVS import

If moving data from a non-Episerver Commerce site to an Episerver Commerce site, you can use the catalog CSV import feature. The CSV import requires you to map fields from the non-Episerver Commerce catalog system to matching catalog metadata fields in the target Episerver Commerce site. This can be problematic because catalog system metadata fields may differ from one implementation to the next, depending on how the catalog system is configured.

See the Commerce section of the Episerver User Guide for information on how to work with catalog imports.

Option 2: Write a utility

You can write a utility to import data from the other system into Episerver Commerce using the Catalog API.

You need to write code to iterate over your collection of non-Episerver Commerce catalog entries. For each non-Episerver Commerce entry, map the appropriate data fields from the other system to the corresponding properties of the Episerver Commerce entry you create. If you choose this option, make sure to copy all config files and references from your Episerver Commerce project to the new utility project.

Example: how to use the Catalog API data transfer objects (DTOs) to create a catalog entry, the CatalogContext being the main entry point to the Catalog system.

private void SampleEntryAdd()
{
  int catalogId = 2;
 
  // Get a CatalogDto object.
  CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto(catalogId, new CatalogResponseGroup(CatalogResponseGroup.ResponseGroup.CatalogInfo));
 
  if (catalogDto.Catalog.Count > 0)
  {
    // Get a CatalogEntryDto object.
    CatalogEntryDto entry = CatalogContext.Current.GetCatalogEntryDto("PRODUCT_CODE",
      new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
 
    if (entry.CatalogEntry.Count == 0)
    {
      // Get a new entry row for your catalog entry.
      CatalogEntryDto.CatalogEntryRow newEntryRow = entry.CatalogEntry.NewCatalogEntryRow();
 
      // Set entry properties.
      newEntryRow.ApplicationId = AppContext.Current.ApplicationId;
      newEntryRow.CatalogId = catalogDto.Catalog[0].CatalogId;
      newEntryRow.ClassTypeId = "Variation";
      newEntryRow.Code = "PRODUCT_CODE";
      newEntryRow.EndDate = DateTime.Now.AddYears(2).ToUniversalTime();
      newEntryRow.IsActive = true;
      newEntryRow.MetaClassId = 32;
      newEntryRow.Name = "PRODUCT_NAME";
      newEntryRow.StartDate = DateTime.UtcNow;
      newEntryRow.TemplateName = "DigitalCameras"; // system-defined template of type 'entry'
      newEntryRow.SetSerializedDataNull();
      if (newEntryRow.RowState == DataRowState.Detached)
        entry.CatalogEntry.AddCatalogEntryRow(newEntryRow);
 
      // Set variation properties.
      CatalogEntryDto.VariationRow newVariationRow = entry.Variation.NewVariationRow();
      newVariationRow.ListPrice = Convert.ToDecimal(1000.00);
      newVariationRow.MaxQuantity = 50;
      newVariationRow.SetMerchantIdNull();
      newVariationRow.MinQuantity = 5;
      newVariationRow.PackageId = 0;
      newVariationRow.TaxCategoryId = 0;
      newVariationRow.TrackInventory = true;
      newVariationRow.WarehouseId = 0;
      newVariationRow.Weight = Convert.ToDouble(4);
      newVariationRow.CatalogEntryId = entry.CatalogEntry[0].CatalogEntryId;
      if (newVariationRow.RowState == DataRowState.Detached)
        entry.Variation.AddVariationRow(newVariationRow);
 
      // Set inventory properties.
      CatalogEntryDto.InventoryRow newInventoryRow = entry.Inventory.NewInventoryRow();
      newInventoryRow.AllowBackorder = false;
      newInventoryRow.AllowPreorder = false;
      newInventoryRow.ApplicationId = AppContext.Current.ApplicationId;
      newInventoryRow.BackorderAvailabilityDate = DateTime.UtcNow;
      newInventoryRow.BackorderQuantity = 0;
      newInventoryRow.InStockQuantity = Convert.ToDecimal(75);
      newInventoryRow.InventoryStatus = 1;
      newInventoryRow.PreorderAvailabilityDate = DateTime.UtcNow;
      newInventoryRow.PreorderQuantity = 0;
      newInventoryRow.ReorderMinQuantity = 15;
      newInventoryRow.ReservedQuantity = 10;
      newInventoryRow.SkuId = "mark_test7";
      if (newInventoryRow.RowState == DataRowState.Detached)
        entry.Inventory.AddInventoryRow(newInventoryRow);
 
      // Set seo properties.
      CatalogEntryDto.CatalogItemSeoRow newSeoRow = entry.CatalogItemSeo.NewCatalogItemSeoRow();
      newSeoRow.ApplicationId = AppContext.Current.ApplicationId;
      newSeoRow.CatalogEntryId = entry.CatalogEntry[0].CatalogEntryId;
      newSeoRow.CatalogNodeId = 62;
      newSeoRow.Description = "DESCRIPTION";
      newSeoRow.LanguageCode = "en-us";
      newSeoRow.Uri = "SEO-FRIENDLY-URL.aspx";
      if (newSeoRow.RowState == DataRowState.Detached)
        entry.CatalogItemSeo.AddCatalogItemSeoRow(newSeoRow);
 
      // Save the entry.
      CatalogContext.Current.SaveCatalogEntry(entry);
 
      // Save the metadata attributes associated with the catalog entry.
      MetaDataContext metaContext = new MetaDataContext();
      MetaClass metaClass = MetaClass.Load(metaContext, "Publications");
      MetaObject metaObj = MetaObject.NewObject(metaContext, entry.CatalogEntry[0].CatalogEntryId, metaClass.Id, "name");
      MetaHelper.SetMetaFieldValue(metaContext, metaObj, "Title", new object[] { "New Book Title" });
      MetaHelper.SetMetaFieldValue(metaContext, metaObj, "ID", new object[] { "New Id" });
      MetaHelper.SetMetaFieldValue(metaContext, metaObj, "Description", new object[] { "New Description" });
      MetaHelper.SetMetaFieldValue(metaContext, metaObj, "Theme", new object[] { "New Book Title" });
      MetaHelper.SetMetaFieldValue(metaContext, metaObj, "Highlight", new object[] { false });
      metaObj.AcceptChanges(metaContext);
 
      // Set the entry node relation.
      CatalogRelationDto relation = new CatalogRelationDto();
      CatalogRelationDto.NodeEntryRelationRow nodeRelation = relation.NodeEntryRelation.NewNodeEntryRelationRow();
      nodeRelation.CatalogId = 2;
      nodeRelation.CatalogEntryId = entry.CatalogEntry[0].CatalogEntryId;
      nodeRelation.CatalogNodeId = 62;
      nodeRelation.SortOrder = 0;
      if (nodeRelation.RowState == DataRowState.Detached)
        relation.NodeEntryRelation.AddNodeEntryRelationRow(nodeRelation);
 
      // Save the relation.
      CatalogContext.Current.SaveCatalogRelationDto(relation);
    }
  }
}

Option 3 

See Using the catalog service in the Episerver Serice API documentation section. 

Importing multiple language metadata

Example: how to create metadata in multiple languages for a catalog, using the MetaHelper.SetMetaFieldValue method.

C#
MetaDataContext MDContext = CatalogContext.MetaDataContext;

    MDContext.UseCurrentUICulture = false;
    //string 
    foreach (string language in Languages)
    {
            MDContext.Language = language;

            MetaHelper.SetMetaFieldValue(metaobj)...

            metaObj.AcceptChanges(MDContext);
    }
    MDContext.UseCurrentUICulture = true; 

Related topic

Comments