The below code is not working for me. Any thing is missing?

            Random random = new Random(DateTime.Now.Millisecond);
            var result = await _createSellableItemPipeline.Run(new CreateSellableItemArgument(random.Next().ToString(), "Hussain Test 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
                addedItem = result.SellableItems.FirstOrDefault(); 
                addedItem.ParentCatalogList = "{59DDADC1-9B88-727E-9E14-3F6CF321AE0F}";
                addedItem.ParentCategoryList = "{871C3B62-CE96-AD61-DABE-10DB020F02C5}";
                addedItem.Brand = "MyTest Brand";
                addedItem.Manufacturer = "My Manufacturer";
                var saveResult = _persistEntityPipeline.Run(new PersistEntityArgument(addedItem), context);

1 Answer 1


You are almost there.

You need to create the relation between the product and the catalog

   var relation = await _createRelationshipPipeline.Run(
                 new RelationshipArgument(categoryID, addedItem.Id, "CategoryToSellableItem")
                      Mode = new RelationshipMode?(RelationshipMode.Create)
                      }, context);                                              

The categoryId should look in this way : Entity-Category-catalogname-categoryname

To create a category you need to use next code:

 var createCategoryCommand = this._commerceCommander.Command<CreateCategoryCommand>();
 var createdCategory = await createCategoryCommand.Process(context.CommerceContext, "catalog id", "category name", "category displayname", "description");

CommerceCommander is declared on your class :

 private readonly CommerceCommander _commerceCommander; 

and is injected on your constructor :

     public YourPipelineBlock(CommerceCommander commerceCommander)
         this._commerceCommander = commerceCommander;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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