public override async Task <SynchronizeProductArgument> Run(SynchronizeProductArgument arg, CommercePipelineExecutionContext context)
        {
            Sitecore.Commerce.Plugin.Catalog.SellableItem product = null;
            var productId = arg.ImportProduct.ProductId.ProposeValidId()
                            .EnsurePrefix(CommerceEntity.IdPrefix <Sitecore.Commerce.Plugin.Catalog.SellableItem>());

            if (await _doesEntityExistPipeline.Run(
                    new FindEntityArgument(typeof(Sitecore.Commerce.Plugin.Catalog.SellableItem), productId),
                    context.CommerceContext.GetPipelineContextOptions()))
            {
                product = await _getSellableItemPipeline.Run(new ProductArgument(arg.Catalog.Id, productId),
                                                             context.CommerceContext.GetPipelineContextOptions());
            }
            else
            {
                var productName  = arg.ImportProduct.ProductName.FirstOrDefault()?.Name;
                var createResult = await _createSellableItemPipeline.Run(
                    new CreateSellableItemArgument(arg.ImportProduct.ProductId.ProposeValidId(), arg.ImportProduct.ProductId,
                                                   productName, ""), context.CommerceContext.GetPipelineContextOptions());

                product = createResult?.SellableItems?.FirstOrDefault(s => s.Id.Equals(productId));
            }

            Condition.Requires <Sitecore.Commerce.Plugin.Catalog.SellableItem>(product)
            .IsNotNull($"{this.Name}: The Product could not be created.");

            product.IsPersisted = true;
            arg.SellableItem    = product;

            return(arg);
        }
        public override Task <EntityView> Run(EntityView arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull($"{Name}: The argument cannot be null.");

            var request = this._viewCommander.CurrentEntityViewArgument(context.CommerceContext);

            var catalogViewsPolicy = context.GetPolicy <KnownCatalogViewsPolicy>();

            var sellableitemstiboattributesviewspolicy = context.GetPolicy <SellableItemStiboAttributesViewsPolicy>();

            var isVariationView = request.ViewName.Equals(catalogViewsPolicy.Variant, StringComparison.OrdinalIgnoreCase);
            var isConnectView   = arg.Name.Equals(catalogViewsPolicy.ConnectSellableItem, StringComparison.OrdinalIgnoreCase);

            // Only proceed if the current entity is a sellable item or Category
            if ((request.Entity is Sitecore.Commerce.Plugin.Catalog.Category) || (request.Entity is Sitecore.Commerce.Plugin.Catalog.SellableItem))
            {
                // Make sure that we target the correct views
                if (string.IsNullOrEmpty(request.ViewName) ||
                    !request.ViewName.Equals(catalogViewsPolicy.Master, StringComparison.OrdinalIgnoreCase) &&
                    !request.ViewName.Equals(catalogViewsPolicy.Details, StringComparison.OrdinalIgnoreCase) &&
                    !request.ViewName.Equals(sellableitemstiboattributesviewspolicy.CategoryAttributes, StringComparison.OrdinalIgnoreCase) &&
                    !isVariationView &&
                    !isConnectView)
                {
                    return(Task.FromResult(arg));
                }
                Sitecore.Commerce.Plugin.Catalog.SellableItem sellableItem = null; Sitecore.Commerce.Plugin.Catalog.Category category = null; var variationId = string.Empty;
                if (request.Entity is Sitecore.Commerce.Plugin.Catalog.SellableItem)
                {
                    sellableItem = (Sitecore.Commerce.Plugin.Catalog.SellableItem)request.Entity;
                }
                if (request.Entity is Sitecore.Commerce.Plugin.Catalog.Category)
                {
                    category = (Sitecore.Commerce.Plugin.Catalog.Category)request.Entity;
                }


                CategoryAttributes component = null;
                if (category != null)
                {
                    component = category.GetComponent <CategoryAttributes>();
                }

                // See if we are dealing with the base sellable item or one of its variations.
                if (sellableItem != null)
                {
                    if (isVariationView && !string.IsNullOrEmpty(arg.ItemId))
                    {
                        variationId = arg.ItemId;
                        component   = sellableItem.GetVariation(variationId).GetComponent <CategoryAttributes>();
                    }
                    else if (!string.IsNullOrEmpty(arg.ItemId) && arg.VersionedItemId != ("-1"))
                    {
                        variationId = arg.ItemId;
                        component   = sellableItem.GetVariation(variationId).GetComponent <CategoryAttributes>();
                    }
                    else
                    {
                        component = sellableItem.GetComponent <CategoryAttributes>(variationId);
                    }
                }

                var  targetView = arg;
                bool isEditView = false;

                #region 16. Category Mapping
                isEditView = !string.IsNullOrEmpty(arg.Action) && arg.Action.Equals(sellableitemstiboattributesviewspolicy.CategoryAttributes, StringComparison.OrdinalIgnoreCase);
                if (!isEditView)
                {
                    // Create a new view and add it to the current entity view.
                    var view = new EntityView
                    {
                        Name          = context.GetPolicy <SellableItemStiboAttributesViewsPolicy>().CategoryAttributes,
                        DisplayName   = "Category Mapping",
                        EntityId      = arg.EntityId,
                        DisplayRank   = 2,
                        EntityVersion = arg.EntityVersion,
                        ItemId        = variationId,
                        Icon          = "piece",
                    };

                    arg.ChildViews.Add(view);
                    targetView = view;
                }

                AddSellableItemProperties.AddPropertiesToViewWithSection(targetView, component, Models.ProductContsants.NonEditableField, nameof(component.SitecoreMappingPath), component.SitecoreMappingPath, component.GetDisplayName(nameof(component.SitecoreMappingPath)));

                AddSellableItemProperties.AddPropertiesToViewWithSection(targetView, component, Models.ProductContsants.NonEditableField, nameof(component.ClassificationType), component.ClassificationType, component.GetDisplayName(nameof(component.ClassificationType)));
                #endregion
            }
            return(Task.FromResult(arg));
        }