I am trying to associate a category to a product inside a minion.
I am using next code :
var catalog = catalogRepository.GetCatalogByName("MyCatalog");
var category = catalogRepository.GetCategoryByName("MyCategory");
Random random = new Random(DateTime.Now.Millisecond);
var result = await _createSellableItemPipeline.Run(new CreateSellableItemArgument(random.Next().ToString(), "Product name", "Product display name", "This is a description of my test product"), context);
SellableItem addedItem = null;
if (result != null) // Null here means it failed to add
{
var catalogL = await _findEntityPipeline.Run(new FindEntityArgument(typeof(Catalog), catalog.Id, false), context) as Catalog;
var categoryL= await _findEntityPipeline.Run(new FindEntityArgument(typeof(Category), category.Id, false), context) as Category;
addedItem = result.SellableItems.FirstOrDefault(); // This is the item which has just been added
addedItem.ParentCatalogList = catalogL.SitecoreId.ToLower();
addedItem.ParentCategoryList = categoryL.SitecoreId.ToLower();
addedItem.Brand = "My Brand";
addedItem.Manufacturer = "My Manufacturer";
var saveResult = _persistEntityPipeline.Run(new PersistEntityArgument(addedItem), context);
var catalogResult = await this._associateSellableItemToParentPipeline.Run(new CatalogReferenceArgument(catalog.Id, category.Id, addedItem.Id));
}
The ittem is created but is not associated to the category. If I associate it manually from the Merchandise dashboard it is working fine. What am I doing wrong?