3

I found that there are no OData API methods for importing new products into the catalog of Sitecore Commerce 9. The only thing you can do is to use /api/DoUxAction() to add new sellable item and then associate this sellable item with inventory. But the JSON object being sent is too big and doesn't seem to be appropriate to import a big set of products.

Is there any way to import bunch of new products to the catalog via OData API in efficient manner?

Thanks.

  • Sitecore Commerce 9 is not available for GA yet. Please wait for official release. – Andrei Paliakou Jan 29 '18 at 11:13
3

tl;dr There are import APIs for both catalogs and inventory sets, but they are designed around importing data that was exported from another Commerce Engine installation. Custom imports could be massaged to match the expected format, but it's probably not worth it.

Importing Catalogs

The ImportCatalog() OData API might do what you need, but the archive file it accepts has very specific contents.

If want to create items from a custom CSV or other source, you're better off creating your own Commerce plugin that exposes a Controller / Command.

Read on for a breakdown of the ImportCatalog() API.

ImportCatalog() accepts:

  1. A zip file via the importFile parameter, the structure of which is defined below
  2. A mode string parameter - if that parameter is "replace", all catalog data will be deleted before the import starts. If mode is anything else, entities will be replaced by their ID.

The expected structure of the file is JSON files of serialized Commerce entities, complete with $type attribution and embedded components.

For most entities, the expected filename is EntityName.*.json (eg. SellableItem.1.json). Entities of this format that will be imported are:

  • RelationshipDefinition.*.json
  • LocalizationEntity.*.json
  • Catalog.*.json
  • Category.*.json
  • SellableItem.*.json

In that order.

Relationships are imported from any zip entries in the Relationships/ folder. Each file is expected to be a serialized List<RelationshipArgument> (from the catalog plugin).

Importing Inventory

Inventory can be imported using ImportInventorySets(), which accepts the same parameters. Entities from it's zip are processed in this order:

  • LocalizationEntity.*.json
  • InventorySet.*.json
  • InventoryInformation.*.json
  • Relationship/*.json (InventorySet -> InventoryInformation)
0

I've just been testing serialisation of entities using the following code:

SellableItem si = new SellableItem();
var blah = si.Deflate();

and it appears to produce the following json:

{
  "$type": "Sitecore.Commerce.Plugin.Catalog.SellableItem, Sitecore.Commerce.Plugin.Catalog",
  "Description": "",
  "ProductId": "",
  "Brand": "",
  "Manufacturer": "",
  "TypeOfGood": "",
  "Tags": {
    "$type": "System.Collections.Generic.List`1[[Sitecore.Commerce.Core.Tag, Sitecore.Commerce.Core]], mscorlib",
    "$values": [

    ]
  },
  "SitecoreId": "b3eb2ddc-03a8-4188-9ef6-b7e7e8807ed3",
  "Components": {
    "$type": "System.Collections.Generic.List`1[[Sitecore.Commerce.Core.Component, Sitecore.Commerce.Core]], mscorlib",
    "$values": [

    ]
  },
  "DateCreated": "2018-03-02T12:56:06.4532853+00:00",
  "DateUpdated": "2018-03-02T12:56:06.4532853+00:00",
  "DisplayName": "",
  "Id": "5ae99f3c30e94c529f387997de592958",
  "Version": 0,
  "IsPersisted": false,
  "Name": "",
  "Policies": {
    "$type": "System.Collections.Generic.List`1[[Sitecore.Commerce.Core.Policy, Sitecore.Commerce.Core]], mscorlib",
    "$values": [

    ]
  }
}

which in theory should be enough for you to generate your json payload.

  • Also, if you're using the API samples, there is a bug whereby you have to increment the Version number even though you're adding a new sellable item. – Ashar Mar 2 '18 at 23:13
0

Apart from ImportCatalog(), please see The Catalog services which is provided by the Sitecore.Commerce.Plugin.Catalog it provides the bunch of commands for catalogs, categories and sellable items management that should allow you to import data from custom sources. Ref. http://commercesdn.sitecore.net/SitecoreXC_9.0/Developers-Guide/Sitecore-XC-9.0_Developers_Guide.pdf, Chapter 13.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.