I have written a program to create Catalog, followed by its category and then tried to create a Relationship(CatalogToCategory) through CreateRelationshipCommand. Im getting the below error.
[17:07:12 ERR] PipelineAbort:Entity not found for Source:Entity-Catalog-CatalogName, Target:Entity-Category-CatalogName-CategoryName, Relationship type:CatalogToCategory
My code below:
Code for creating catalog:
using (CommandActivity.Start(context.CommerceContext,
createCatalogCommand))
{
catalog = await
createCatalogCommand.Process(context.CommerceContext,
item.Name, item.DisplayName);
if (catalog != null)
{
CreateCategories(catalog, item, context);
}
}
code for creating categories:
foreach (var _category in item.Categories)
{
Category category = null;
using (CommandActivity.Start(context.CommerceContext,
createCategoryCommand))
{
category = await
createCategoryCommand.Process(context.CommerceContext,
catalog.Id, _category, _category, string.Empty);
}
var relationShip = CreateRelationship(context, catalog, category);
}
code for creating relationship:
var relation = createRelationshipCommand.
Process(context.CommerceContext,
catalog.Id, //Entity-Catalog-CatalogName
category.Id,//Entity-Category-CatalogName-CategoryName
"CatalogToCategory");
code for creating relationship(Using associateCategoryToParentCommand):
var association = await associateCategoryToParentCommand.Process(context.CommerceContext,
catalog.Id, catalog.Id, category.Id).ConfigureAwait(true);
Got the same error when using "AssociateCategoryToParentCommand" instead of "CreateRelationshipCommand". Please find the error message below.
Is there anything I'm missing out here? Should I run any other command before/after this? Am I using the right parameters?
Both the items(catalog and category) are created in the database. Also, the catalog created is visible in BizFx tool. But the category created is not.
Is there any simple way to map catalog to categories, categories to sellable items and to show them in BizFx tool through code.
Im using Sitecore Commerce 9.2 version.