예제 #1
0
        public async Task DisassociateParentCategories(string catalogName, Category category, CommerceContext context)
        {
            var catalogCommerceId = $"{CommerceEntity.IdPrefix<Catalog>()}{catalogName}";
            await _deleteRelationshipCommand.Process(context, catalogCommerceId, category.Id, "CategoryToCategory");

            var parentCategorySitecoreIds = category?.ParentCategoryList?.Split('|');

            if (parentCategorySitecoreIds == null || parentCategorySitecoreIds.Length == 0)
            {
                return;
            }

            var categoryList = await _getManagedListCommand.Process(context, CommerceEntity.ListName <Category>()).ConfigureAwait(false);

            var allCategories = categoryList?.Items?.Cast <Category>();

            if (allCategories != null)
            {
                foreach (var parentCategorySitecoreId in parentCategorySitecoreIds)
                {
                    var parentCategory = allCategories.FirstOrDefault(c => c.SitecoreId == parentCategorySitecoreId);
                    if (parentCategory != null)
                    {
                        await _deleteRelationshipCommand.Process(context, parentCategory.Id, category.Id, "CategoryToCategory");
                    }
                }
            }
        }
예제 #2
0
        public async Task DisassociateParentCategories(SellableItem sellableItem, CommerceContext context)
        {
            var parentCategorySitecoreIds = sellableItem?.ParentCategoryList?.Split('|');

            if (parentCategorySitecoreIds == null || parentCategorySitecoreIds.Length == 0)
            {
                return;
            }

            var categoryList = await _getManagedListCommand.Process(context, CommerceEntity.ListName <SellableItem>()).ConfigureAwait(false);

            var allCategories = categoryList?.Items?.Cast <Category>();

            if (allCategories != null)
            {
                foreach (var parentCategorySitecoreId in parentCategorySitecoreIds)
                {
                    var parentCategory = allCategories.FirstOrDefault(c => c.SitecoreId == parentCategorySitecoreId);
                    if (parentCategory != null)
                    {
                        await _deleteRelationshipCommand.Process(context, parentCategory.Id, sellableItem.Id, "CategoryToSellableItem");
                    }
                }
            }
        }
예제 #3
0
        public override async Task <ImportEntityArgument> Run(ImportEntityArgument arg, CommercePipelineExecutionContext context)
        {
            var commerceEntity = arg.ImportHandler.GetCommerceEntity();

            if (arg.ImportHandler.ParentEntityIds == null ||
                !arg.ImportHandler.ParentEntityIds.Any() ||
                (!(commerceEntity is Category) && !(commerceEntity is SellableItem)))
            {
                return(await Task.FromResult(arg));
            }

            if (commerceEntity.HasComponent <ParentEntitiesComponent>())
            {
                var component = commerceEntity.GetComponent <ParentEntitiesComponent>();

                var allIds = arg.ImportHandler.ParentEntityIds.SelectMany(x => x.Value).Distinct().ToList();

                var relationshipNamePostfix = "To" + commerceEntity.GetType().Name;

                foreach (var componentEntityId in component.EntityIds)
                {
                    if (!allIds.Contains(componentEntityId))
                    {
                        var relationshipName = string.Empty;

                        if (componentEntityId.StartsWith(CommerceEntity
                                                         .IdPrefix <Sitecore.Commerce.Plugin.Catalog.Catalog>()))
                        {
                            relationshipName = typeof(Sitecore.Commerce.Plugin.Catalog.Catalog).Name +
                                               relationshipNamePostfix;
                        }
                        else if (componentEntityId.StartsWith(CommerceEntity
                                                              .IdPrefix <Category>()))
                        {
                            relationshipName = typeof(Category).Name +
                                               relationshipNamePostfix;
                        }

                        if (!string.IsNullOrEmpty(relationshipName))
                        {
                            await _deleteRelationshipCommand.Process(context.CommerceContext,
                                                                     componentEntityId,
                                                                     commerceEntity.Id,
                                                                     relationshipName)
                            .ConfigureAwait(false);
                        }
                    }
                }
            }

            return(await Task.FromResult(arg));
        }