public override async Task <List <BreadcrumbModel> > Run(string arg, CommercePipelineExecutionContext context)
        {
            var result = new List <BreadcrumbModel>();

            if (string.IsNullOrWhiteSpace(arg))
            {
                return(result);
            }

            var currentItem =
                await _findEntityPipeline.Run(new FindEntityArgument(typeof(CatalogItemBase), arg, false), context)
                .ConfigureAwait(false) as CatalogItemBase;

            if (currentItem == null)
            {
                return(result);
            }

            var children = await GetChildren(currentItem, context).ConfigureAwait(false);

            foreach (var itm in children)
            {
                var version          = 1;
                var commerceEntities =
                    await _findEntityVersionsPipeline.Run(new FindEntityArgument(itm.GetType(), itm.Id, false),
                                                          context);

                if (commerceEntities != null)
                {
                    var itemVersion = commerceEntities.LastOrDefault();
                    version = itemVersion?.Version ?? 1;
                }

                result.Add(itm.ToBreadcrumbModel(version));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public override async Task <List <BreadcrumbModel> > Run(string arg, CommercePipelineExecutionContext context)
        {
            var result    = new List <BreadcrumbModel>();
            var childList = new List <CatalogItemBase>();


            if (arg.StartsWith("Entity-"))
            {
                var currentItem =
                    await _findEntityPipeline.Run(new FindEntityArgument(typeof(CatalogItemBase), arg, false), context)
                    .ConfigureAwait(false) as CatalogItemBase;

                if (currentItem == null)
                {
                    result.Add(new BreadcrumbModel()
                    {
                        Href = "/", Icon = "si si-temple", IsActive = false, Name = "COMMERCE", EntityId = "root"
                    });
                    return(result);
                }

                var model = new List <CatalogItemBase>();

                childList.Add(currentItem);
                await GetParents(currentItem, model, context).ConfigureAwait(false);

                childList.AddRange(model);

                if (currentItem != null && currentItem.HasComponent <ExtendedCatalogItemComponent>())
                {
                    var component = currentItem.GetComponent <ExtendedCatalogItemComponent>();
                    var catalog   = await _findEntityPipeline.Run(new FindEntityArgument(typeof(CatalogItemBase), component.ParentCatalogEntitiesList, false), context) as CatalogItemBase;

                    childList.Add(catalog);
                }
            }

            result.Add(new BreadcrumbModel()
            {
                Href = "/", Icon = "si si-temple", IsActive = false, Name = "COMMERCE", EntityId = "root"
            });
            childList.Reverse();

            foreach (var itm in childList)
            {
                var version          = 1;
                var commerceEntities =
                    await _findEntityVersionsPipeline.Run(new FindEntityArgument(itm.GetType(), itm.Id, false),
                                                          context);

                if (commerceEntities != null)
                {
                    var itemVersion = commerceEntities.LastOrDefault();
                    version = itemVersion?.Version ?? 1;
                }

                result.Add(itm.ToBreadcrumbModel(version));
            }

            return(result);
        }