コード例 #1
0
        public override async Task <ProductComparison> Run(AddToProductCompareArgument arg, CommercePipelineExecutionContext context)
        {
            Contract.Requires(arg != null);
            Contract.Requires(context != null);

            Condition.Requires(arg).IsNotNull($"{Name}: The arg can not be null");
            Condition.Requires(arg.ProductId).IsNotNull($"{Name}: The product id can not be null");
            Condition.Requires(arg.CompareCollection).IsNotNull($"{Name}: The Compare Collection can not be null");

            var sellableItem = await _getSellableItemPipeline.Run(BuildProductArgument(arg), context).ConfigureAwait(false);

            if (sellableItem == null)
            {
                context.Logger.LogWarning($"ProductCompare: Unable to find sellable item to add to collection:{arg.CatalogName}-{arg.ProductId}-{arg.VariantId}");
                return(arg.CompareCollection);
            }

            var list = arg.CompareCollection.Products.ToList();

            if (list.Any(x => x.Id == sellableItem.Id))
            {
                context.Logger.LogDebug($"{Name}: SellableItem already exists in compare collection, no further action to take");
                return(arg.CompareCollection);
            }

            var addArg = new ListEntitiesArgument(new List <string> {
                sellableItem.Id
            }, arg.CompareCollection.Name);
            await _addListEntitiesPipeline.Run(addArg, context).ConfigureAwait(false);

            return(arg.CompareCollection);
        }
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="arg">
        /// The JobInfoArgument argument.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="JobInstance"/>.
        /// </returns>
        public override async Task <JobInstance> Run(JobInfoArgument arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull("JobInfoArgument: The argument cannot be null.");
            Condition.Requires(arg.JobInstance).IsNotNull("JobInstance cannot be null.");
            Condition.Ensures(arg.JobInstance.Status.Equals("queued", StringComparison.OrdinalIgnoreCase))
            .IsFalse("Job status has not changed. Make sure job processor exists.");
            var jobInstance = arg.JobInstance;
            //Remove the JobInstance from WatchList
            var knownJobInstanceListsPolicy = context.GetPolicy <KnownJobInstanceListsPolicy>();
            var component = jobInstance.GetComponent <TransientListMembershipsComponent>();

            if (jobInstance.Status.Equals("Success", StringComparison.OrdinalIgnoreCase))
            {
                component.Memberships.Add(knownJobInstanceListsPolicy.SuccessJobs);
            }
            else
            {
                component.Memberships.Add(knownJobInstanceListsPolicy.FailedJobs);
            }
            var listEntitiesArgument = new ListEntitiesArgument(new string[1]
            {
                arg.JobInstance.Id
            }, knownJobInstanceListsPolicy.QueuedJobs);

            listEntitiesArgument = await _removeListEntitiesPipeline.Run(listEntitiesArgument, context);

            jobInstance.EndDateTime = DateTime.Now;
            jobInstance.ElapsedTime = (jobInstance.EndDateTime - jobInstance.StartDateTime).GetValueOrDefault(TimeSpan.Zero);
            var persistEntityArgument = await _persistEntityPipeline.Run(new PersistEntityArgument(jobInstance), context);

            context.CommerceContext.AddEntity(jobInstance);
            return(jobInstance);
        }
コード例 #3
0
        public override async Task <CatalogContentArgument> Run(SynchronizeCatalogArgument arg, CommercePipelineExecutionContext context)
        {
            var ids    = arg.MasterProducts.Select(p => $"{arg.CatalogId}_{p.Id.ToString()}");
            var addArg = new ListEntitiesArgument(ids, "ProductUpdatesList");
            await _addListEntitiesPipeline.Run(addArg, context);

            return(arg);
        }
コード例 #4
0
        public override async Task <PersistEntityArgument> Run(PersistEntityArgument arg, CommercePipelineExecutionContext context)
        {
            var policy = context.CommerceContext.GetPolicy <MappingPolicyBase>();
            ListEntitiesArgument listArgument = new ListEntitiesArgument(new string[1] {
                arg.Entity.Id
            }, policy.SyncedItemsList);
            ListEntitiesArgument addToListResult = await this._addListEntitiesPipeline.Run(listArgument, context);

            return(arg);
        }
        /// <summary>
        /// Moves to problem list.
        /// </summary>
        /// <param name="salesActivity">The sales activity.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        protected async virtual Task MoveToProblemList(SalesActivity salesActivity, CommercePipelineExecutionContext context)
        {
            var transientMemberships = salesActivity.GetComponent <TransientListMembershipsComponent>();

            transientMemberships.Memberships.Remove(context.GetPolicy <KnownOrderListsPolicy>().SettleSalesActivities);
            transientMemberships.Memberships.Add(context.GetPolicy <KnownOrderListsPolicy>().ProblemSalesActivities);

            var removeArg = new ListEntitiesArgument(new List <string> {
                salesActivity.Id
            }, context.GetPolicy <KnownOrderListsPolicy>().SettleSalesActivities);

            await this._removePipeline.Run(removeArg, context);
        }
コード例 #6
0
        public override async Task <InventorySet> Run(CreateStoreInventorySetArgument arg, CommercePipelineExecutionContext context)
        {
            CreateStoreInventorySetBlock inventorySetBlock = this;

            string id        = CommerceEntity.IdPrefix <InventorySet>() + arg.Name;
            var    doesExist = await inventorySetBlock._doesEntityExistPipeline.Run(new FindEntityArgument(typeof(InventorySet), id, false), context);

            if (doesExist)
            {
                CommercePipelineExecutionContext executionContext = context;
                CommerceContext commerceContext = context.CommerceContext;
                string          validationError = context.GetPolicy <KnownResultCodes>().ValidationError;
                //string commerceTermKey = "InventorySetNameAlreadyInUse";
                object[] args = new object[1] {
                    (object)arg.Name
                };
                string defaultMessage = string.Format("Inventory set name {0} is already in use.", (object)arg.Name);
                return(new InventorySet()
                {
                    Id = CommerceEntity.IdPrefix <InventorySet>() + arg.Name
                });
            }


            InventorySet inventorySet = new InventorySet();
            string       str          = id;

            inventorySet.Id = str;
            string name1 = arg.Name;

            inventorySet.FriendlyId = name1;
            string name2 = arg.Name;

            inventorySet.Name = name2;
            string displayName = arg.DisplayName;

            inventorySet.DisplayName = displayName;
            string description = arg.Description;

            inventorySet.Description = description;

            // Set component for store
            StoreDetailsComponent storeDetailsComponent = new StoreDetailsComponent()
            {
                StoreName   = arg.StoreName,
                Address     = arg.Address,
                City        = arg.City,
                State       = arg.State,
                StateCode   = arg.Abbreviation,
                ZipCode     = arg.ZipCode,
                CountryCode = arg.CountryCode,
                Long        = arg.Long,
                Lat         = arg.Lat
            };

            inventorySet.SetComponent(storeDetailsComponent);

            PersistEntityArgument persistEntityArgument = await inventorySetBlock._persistEntityPipeline.Run(new PersistEntityArgument(inventorySet), context);

            context.CommerceContext.AddEntity(inventorySet);
            ListEntitiesArgument entitiesArgument1 = new ListEntitiesArgument((IEnumerable <string>) new string[1]
            {
                inventorySet.Id
            }, CommerceEntity.ListName <InventorySet>());
            ListEntitiesArgument entitiesArgument2 = await inventorySetBlock._addListEntitiesPipeline.Run(entitiesArgument1, context);

            return(inventorySet);
        }