Use the Episerver Service API to import the catalog XML.
Catalog data from another 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
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.
[Legacy version 11 and lower - ILinksRepository and ApplicationId were removed from version 12.]
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);
}