This content is archived. See latest version here

Last updated: May 05 2015

This section provides an overview of different options when importing catalog data between e-commerce sites, including the addition of meta data in multiple languages.

Classes referred to here are available in the following namespaces:

It is not recommended to import data directly into the catalog system database, unless you have a full understanding of how the database works.

Import scenarios

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

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

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

Option 1

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

Refer to the Commerce section of the EPiServer User Guide for more information on how to work with catalog imports.

Option 2

Another option to import data is to write a utility tool importing the data from the other system into EPiServer Commerce using the Catalog API.

You would 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 of the 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 meta data 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);
    }
  }
}

Importing multiple language meta data

Example: how to create meta data 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;

Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/