I'm not sure that you need to get Sitecore Item to load subcategoroies.
But you may use the concept of Commerce Lists to load children categories. For Model you've provided in your question you may use list CategoryToCategory
that will load all subcategories for your category. You can try to use Postman for your model. API URL will look like this:
{{ServiceHost}}/{{ShopsApi}}/GetList(id='CategoryToCategory-{FriendlyId}',type='Sitecore.Commerce.Plugin.Catalog.Category, Sitecore.Commerce.Plugin.Catalog',skip=0,take=100)?$expand=Items
in your example {FriendlyId}
equals to X-X
.
If you need to call the same command from code, then you can use the following snippet:
await findEntitiesInListCommand.Process(commerceContext: commerceContext, type: typeof(Sitecore.Commerce.Plugin.Catalog.Category).ToString(), listName: "CategoryToCategory", skip: 0, take: 100);
You may then use the code you've provided in your question to load additional information: Category pluginCategory = await _getCategoryCommand.Process(context, category.Id);
where id is Id = Name.ToCategoryId(ParentCatalogId);
Update on CategoryToCategory string
I haven't found any documentation on this but explored it while looking at SitecoreCommerce_SharedEnvironments
database. I was looking through default Commerce pipelines and found following block in InitializeRelationshipDefinitionsBlock
:
public override async Task<string> Run(string arg, CommercePipelineExecutionContext context)
{
InitializeRelationshipDefinitionsBlock definitionsBlock = this;
string relationship1 = await definitionsBlock.CreateRelationship("CatalogToCategory", "Represents a relationship between a catalog and a category", typeof (Sitecore.Commerce.Plugin.Catalog.Catalog), typeof (Category), context, false, false);
string relationship2 = await definitionsBlock.CreateRelationship("CatalogToSellableItem", "Represents a relationship between a catalog and a sellable item", typeof (Sitecore.Commerce.Plugin.Catalog.Catalog), typeof (SellableItem), context, false, false);
string relationship3 = await definitionsBlock.CreateRelationship("CategoryToCategory", "Represents a relationship between a category and another category", typeof (Category), typeof (Category), context, false, false);
string relationship4 = await definitionsBlock.CreateRelationship("CategoryToSellableItem", "Represents a relationship between a category and a sellable item", typeof (Category), typeof (SellableItem), context, false, false);
string relationship5 = await definitionsBlock.CreateRelationship("PromotionBookToCatalog", "Represents a relationship between a promotion book and a catalog", typeof (PromotionBook), typeof (Sitecore.Commerce.Plugin.Catalog.Catalog), context, false, false);
string relationship6 = await definitionsBlock.CreateRelationship("PriceBookToCatalog", "Represents a relationship between a price book and a catalog", typeof (PriceBook), typeof (Sitecore.Commerce.Plugin.Catalog.Catalog), context, false, false);
return arg;
}