0

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.

enter image description here

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.

3
  • try AssociateCategoryToParentCommand instead of CreateRelationshipCommand. Dec 26 '19 at 9:03
  • Hi @VipinBanka, thanks for your reply. Still getting that same error message when using "AssociateCategoryToParentCommand". Am I providing the right parameters? var relation = await associateCategoryToParentCommand.Process(context.CommerceContext, catalog.Id, catalog.Id, category.Id).ConfigureAwait(true); Dec 26 '19 at 15:32
  • Hi @VipinBanka, yes you are right. "AssociateCategoryToParentCommand" works for me. The mistake I did was, forgot to Initialize the environment which I newly created. Thanks for your help. Dec 27 '19 at 1:13
0

Looks like your commerce engine was not initialized properly.

You have to reinitialize it.

Steps you can find here: https://doc.sitecore.com/en/developers/90/sitecore-experience-commerce/clean-and-initialize-the-environment.html

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.