Loading...
Area: Episerver Commerce
Applies to versions: 10
Other versions:

Importing catalog data

Recommendations [hide]

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: 

  • Mediachase.Commerce.Catalog
  • Mediachase.Commerce.Storage

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 using these methods.

  • 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. See Catalog service in the Episerver Service API documentation section.

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: CSV 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 Importing and exporting a catalog to learn 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.

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 corresponding properties of the Episerver Commerce entry you create. 

First, you need some typed models for your products and variants. It would look something like this.

[CatalogContentType(GUID = "D770BBC1-25C6-46D2-8249-9EB47AC6C965", MetaClassName = "MyCustomProduct")]
public class MyCustomProduct : ProductContent
  {
    public virtual string Publisher { get; set; }
  }

[CatalogContentType(GUID = "1C41A7A7-3671-4981-838B-363A6DB6AFAB", MetaClassName = "MyCustomVariation")]
public class MyCustomVariation : VariationContent
  {
    public virtual string Type { get; set; }
  }

The following adds a product with a variation of the types above to your Episerver Commerce site.

private readonly IContentRepository contentRepository;
private readonly ILinksRepository linksRepository;
private readonly IInventoryService inventoryService;
private readonly IPriceDetailService priceDetailService;
private void AddEntry()
  {
    ContentReference parentCategoryLink; // Get a reference to the node you want to add the product to.

    // Add product
    var product = contentRepository.GetDefault<MyCustomProduct>(parentCategoryLink, CultureInfo.GetCultureInfo("en-US"));
    product.Name = "Product name";
    product.Code = "123-456";
    product.Publisher = "Episerver";
    contentRepository.Save(product, SaveAction.Publish, AccessLevel.NoAccess);

    // Add variation
    var variation = contentRepository.GetDefault<MyCustomVariation>(parentCategoryLink, CultureInfo.GetCultureInfo("en-US"));
    variation.Name = "Variation name";
    variation.Code = "654-321";
    variation.Type = "Paperback";
    variation.MaxQuantity = 50;
    contentRepository.Save(variation, SaveAction.Publish, AccessLevel.NoAccess);

    // Add relation between product and variant
    var newVariation = new ProductVariation
      {
        SortOrder = 1,
        Source = product.ContentLink,
        Target = variation.ContentLink
      };
    linksRepository.UpdateRelation(newVariation);

    // Add inventory information
    var inventoryRecord = new InventoryRecord
      {
        CatalogEntryCode = variation.Code,
        PurchaseAvailableQuantity = 10,
        PurchaseAvailableUtc = DateTime.UtcNow,
        WarehouseCode = "default"
      };
    inventoryService.Insert(new[] { inventoryRecord });
            
    // Add price information
    var priceDetailValue = new PriceDetailValue
      {
        CatalogKey = new CatalogKey(AppContext.Current.ApplicationId, variation.Code),
        MarketId = new MarketId("US"),
        CustomerPricing = CustomerPricing.AllCustomers,
        ValidFrom = DateTime.UtcNow,
        UnitPrice = new Money(1m, Currency.USD)
      };
    priceDetailService.Save(priceDetailValue);
  }

To improve performance by eliminating previous versions, see Clear version history for saved catalog content.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 24, 2016

Recommendations [hide]