public override async Task <bool> Run(UpdateIngenicoPaymentArgument arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull($"{this.Name}: The argument cannot be null."); // Todo: Authenticate request // Fulfill pre-condition: get cart Order order = await getOrderPipeline.Run(arg.OrderId, context).ConfigureAwait(false); if (order == null) { await context.CommerceContext.AddMessage(context.CommerceContext.GetPolicy <KnownResultCodes>().Error, "EntityNotFound", new object[] { arg.OrderId }, $"Entity {0} was not found."); return(false); } var paymentStatus = order.GetComponent <IngenicoPaymentComponent>(); paymentStatus.Brand = arg.Brand; paymentStatus.TransactionStatus = arg.Status; PersistEntityArgument result = await persistEntityPipeline.Run(new PersistEntityArgument(order), context); return(true); }
/// <summary> /// Runs the specified argument. /// </summary> /// <param name="arg">The argument.</param> /// <param name="context">The context.</param> /// <returns></returns> public override async Task <FulfillmentFeeBook> Run(FulfillmentFeeBook arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull(string.Format("{0}: The Fulfillment fee book can not be null", this.Name)); PersistEntityArgument persistEntityArgument = await this._persistEntityPipeline.Run(new PersistEntityArgument(arg), context); context.CommerceContext.AddEntity(arg); return(arg); }
public async Task <bool> Process(CommerceContext commerceContext, IEnumerable <CommerceEntity> items) { using (CommandActivity.Start(commerceContext, this)) { commerceContext.Logger.LogInformation($"Called - {nameof(PersistEntityBulkCommand)}."); foreach (var item in items) { commerceContext.ClearMessages(); await PerformTransaction(commerceContext, async() => { var arg = new PersistEntityArgument(item); await Pipeline <IPersistEntityPipeline>().Run(arg, commerceContext.PipelineContextOptions); }); } commerceContext.Logger.LogInformation($"Completed - {nameof(PersistEntityBulkCommand)}."); return(true); } }
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); }
public override async Task <bool> Run(SellableItemInventorySetsArgument argument, CommercePipelineExecutionContext context) { AssociateStoreInventoryToSellablteItemBlock associateStoreInventoryToSellablteItemBlock = this; Condition.Requires(argument).IsNotNull(string.Format("{0}: The argument can not be null", argument)); string sellableItemId = argument.SellableItemId; CommerceEntity entity = await associateStoreInventoryToSellablteItemBlock._findEntityPipeline.Run(new FindEntityArgument(typeof(SellableItem), sellableItemId, false), context).ConfigureAwait(false); CommercePipelineExecutionContext executionContext; if (!(entity is SellableItem)) { executionContext = context; CommerceContext commerceContext = context.CommerceContext; string validationError = context.GetPolicy <KnownResultCodes>().ValidationError; string commerceTermKey = "EntityNotFound"; object[] args = new object[1] { argument.SellableItemId }; string defaultMessage = string.Format("Entity {0} was not found.", argument.SellableItemId); executionContext.Abort(await commerceContext.AddMessage(validationError, commerceTermKey, args, defaultMessage).ConfigureAwait(false), context); executionContext = null; return(false); } SellableItem sellableItem = entity as SellableItem; if ((string.IsNullOrEmpty(argument.VariationId)) & sellableItem.HasComponent <ItemVariationsComponent>()) { executionContext = context; executionContext.Abort(await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().ValidationError, "AssociateInventoryWithVariant", new object[0], "Can not associate inventory to the base sellable item. Use one of the variants instead.").ConfigureAwait(false), context); executionContext = null; return(false); } ItemVariationComponent sellableItemVariation = null; if (argument.VariationId != null) { sellableItemVariation = sellableItem.GetVariation(argument.VariationId); if (!string.IsNullOrEmpty(argument.VariationId) && sellableItemVariation == null) { executionContext = context; CommerceContext commerceContext = context.CommerceContext; string validationError = context.GetPolicy <KnownResultCodes>().ValidationError; string commerceTermKey = "ItemNotFound"; object[] args = new object[1] { argument.VariationId }; string defaultMessage = string.Format("Item '{0}' was not found.", argument.VariationId); executionContext.Abort(await commerceContext.AddMessage(validationError, commerceTermKey, args, defaultMessage).ConfigureAwait(false), context); executionContext = null; return(false); } } List <InventoryAssociation> inventoryAssociations = new List <InventoryAssociation>(); foreach (var inventorySetId in argument.InventorySetIds) { bool isUpdate = false; Random rnd = new Random(); InventoryInformation inventoryInformation = await associateStoreInventoryToSellablteItemBlock._getInventoryInformationCommand .Process(context.CommerceContext, inventorySetId, argument.SellableItemId, argument.VariationId, false) .ConfigureAwait(false); IFindEntitiesInListPipeline entitiesInListPipeline = associateStoreInventoryToSellablteItemBlock._findEntitiesInListPipeline; FindEntitiesInListArgument entitiesInListArgument1 = new FindEntitiesInListArgument(typeof(SellableItem), string.Format("{0}-{1}", "InventorySetToInventoryInformation", inventorySetId.SimplifyEntityName()), 0, int.MaxValue); entitiesInListArgument1.LoadEntities = false; CommercePipelineExecutionContext context1 = context; FindEntitiesInListArgument entitiesInListArgument2 = await entitiesInListPipeline.Run(entitiesInListArgument1, context1).ConfigureAwait(false); if (inventoryInformation != null && entitiesInListArgument2 != null) { List <ListEntityReference> entityReferences = entitiesInListArgument2.EntityReferences.ToList(); string id = inventoryInformation.Id; if (entityReferences != null && entityReferences.Any(er => er.EntityId == id)) { inventoryInformation.Quantity = rnd.Next(50); isUpdate = true; } } if (!isUpdate) { string inventorySetName = string.Format("{0}-{1}", inventorySetId.SimplifyEntityName(), sellableItem.ProductId); if (!string.IsNullOrEmpty(argument.VariationId)) { inventorySetName += string.Format("-{0}", argument.VariationId); } InventoryInformation inventoryInformation1 = new InventoryInformation(); inventoryInformation1.Id = string.Format("{0}{1}", CommerceEntity.IdPrefix <InventoryInformation>(), inventorySetName); inventoryInformation1.FriendlyId = inventorySetName; EntityReference entityReference1 = new EntityReference(inventorySetId, ""); inventoryInformation1.InventorySet = entityReference1; EntityReference entityReference2 = new EntityReference(argument.SellableItemId, ""); inventoryInformation1.SellableItem = entityReference2; string variationId = argument.VariationId; inventoryInformation1.VariationId = variationId; inventoryInformation1.Quantity = rnd.Next(50); inventoryInformation = inventoryInformation1; } inventoryInformation.GetComponent <TransientListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <InventoryInformation>()); PersistEntityArgument persistEntityArgument1 = await associateStoreInventoryToSellablteItemBlock._persistEntityPipeline.Run(new PersistEntityArgument((CommerceEntity)inventoryInformation), context).ConfigureAwait(false); RelationshipArgument relationshipArgument = await associateStoreInventoryToSellablteItemBlock._createRelationshipPipeline.Run(new RelationshipArgument(inventorySetId, inventoryInformation.Id, "InventorySetToInventoryInformation"), context).ConfigureAwait(false); InventoryAssociation inventoryAssociation = new InventoryAssociation() { InventoryInformation = new EntityReference(inventoryInformation.Id, ""), InventorySet = new EntityReference(inventorySetId, "") }; inventoryAssociations.Add(inventoryAssociation); } (sellableItemVariation != null ? sellableItemVariation.GetComponent <InventoryComponent>() : sellableItem.GetComponent <InventoryComponent>()).InventoryAssociations.AddRange(inventoryAssociations); PersistEntityArgument persistEntityArgument2 = await associateStoreInventoryToSellablteItemBlock._persistEntityPipeline.Run(new PersistEntityArgument(sellableItem), context).ConfigureAwait(false); return(true); }
public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context) { int limitValue = -999; string strCode = string.Empty; string regClassCode = string.Empty; EntityView entityView1 = entityView; if (string.IsNullOrEmpty(entityView1 != null ? entityView1.Action : null) || !entityView.Action.Equals(context.GetPolicy <KnownCouponActionsPolicy>().AddPublicCoupon, StringComparison.OrdinalIgnoreCase) || (!entityView.Name.Equals(context.GetPolicy <KnownCouponViewsPolicy>().PublicCoupons, StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(entityView.EntityId))) { return(entityView); } Promotion promotion = context.CommerceContext.GetObject <Promotion>(p => p.Id.Equals(entityView.EntityId, StringComparison.OrdinalIgnoreCase)); if (promotion == null) { return(entityView); } ViewProperty code = entityView.Properties.FirstOrDefault(p => p.Name.Equals("Code", StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(code != null ? code.Value : null)) { strCode = code == null ? "Code" : code.DisplayName; string result = await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().ValidationError, "InvalidOrMissingPropertyValue", new object[1] { strCode }, "Invalid or missing value for property 'Code'."); return(entityView); } ViewProperty limitViewProperty = entityView.Properties.FirstOrDefault(p => p.Name.Equals("Coupon Usage Limit", StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(limitViewProperty != null ? limitViewProperty.Value : null)) { string errorCode = limitViewProperty == null ? "Coupon Usage Limit" : limitViewProperty.DisplayName; string result = await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().ValidationError, "InvalidOrMissingPropertyValue", new object[1] { errorCode }, "Invalid or missing value for property 'Code'."); return(entityView); } if (limitViewProperty.Value != null) { bool isSuccess = int.TryParse(limitViewProperty.Value, out limitValue); if (!isSuccess) { string errorCode = code == null ? "Coupon Usage Limit" : limitViewProperty.DisplayName; string result = await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().ValidationError, "InvalidOrMissingPropertyValue", new object[1] { errorCode }, "Invalid or missing value for property 'Coupon Usage Limit'."); return(entityView); } } CommerceContext commerceContext = context.CommerceContext; string couponCode = code != null ? code.Value : null; Promotion promotion2 = await _addPublicCouponCommand.Process(commerceContext, promotion, couponCode); string couponId = $"{CommerceEntity.IdPrefix<Coupon>()}{couponCode}"; var couponData = await _findEntityPipeline.Run(new FindEntityArgument(typeof(Coupon), couponId, false), context); if (couponData != null && couponData is Coupon) { var coupon = couponData as Coupon; if (coupon != null) { coupon.Policies = new List <Policy>() { new LimitUsagesPolicy() { LimitCount = limitValue } }; PersistEntityArgument persistEntityArgument = await _persistEntityPipeline.Run(new PersistEntityArgument((CommerceEntity)coupon), context); } } return(entityView); }
public override async Task <RelationshipArgument> Run( RelationshipArgument arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull(Name + ": The argument can not be null"); Condition.Requires(arg.TargetName).IsNotNullOrEmpty(Name + ": The target name can not be null or empty"); Condition.Requires(arg.SourceName).IsNotNullOrEmpty(Name + ": The source name can not be null or empty"); Condition.Requires(arg.RelationshipType).IsNotNullOrEmpty(Name + ": The relationship type can not be null or empty"); if (!((IEnumerable <string>) new string[4] { CatalogToCategory, CatalogToSellableItem, CategoryToCategory, CategoryToSellableItem }) .Contains(arg.RelationshipType, StringComparer.OrdinalIgnoreCase)) { return(arg); } CatalogItemBase source = await _findEntityPipeline.Run(new FindEntityArgument(typeof(CatalogItemBase), arg.SourceName, false), context) as CatalogItemBase; List <string> stringList = new List <string>(); if (arg.TargetName.Contains("|")) { string[] strArray = arg.TargetName.Split('|'); stringList.AddRange(strArray); } else { stringList.Add(arg.TargetName); } ValueWrapper <bool> sourceChanged = new ValueWrapper <bool>(false); if (!source.HasComponent <ExtendedCatalogItemComponent>()) { source.SetComponent(new ExtendedCatalogItemComponent()); } var sourceComponent = source.GetComponent <ExtendedCatalogItemComponent>(); foreach (string entityId in stringList) { CatalogItemBase catalogItemBase = await _findEntityPipeline.Run(new FindEntityArgument(typeof(CatalogItemBase), entityId, false), context) as CatalogItemBase; if (source != null && catalogItemBase != null) { if (!catalogItemBase.HasComponent <ExtendedCatalogItemComponent>()) { catalogItemBase.SetComponent(new ExtendedCatalogItemComponent()); } var catalogItemBaseComponent = catalogItemBase.GetComponent <ExtendedCatalogItemComponent>(); ValueWrapper <bool> changed = new ValueWrapper <bool>(false); if (arg.RelationshipType.Equals(CatalogToCategory, StringComparison.OrdinalIgnoreCase)) { sourceComponent.ChildrenCategoryEntitiesList = UpdateHierarchy(arg, catalogItemBase.Id, sourceComponent.ChildrenCategoryEntitiesList, sourceChanged); catalogItemBaseComponent.ParentCatalogEntitiesList = UpdateHierarchy(arg, source.Id, catalogItemBaseComponent.ParentCatalogEntitiesList, changed); } else if (arg.RelationshipType.Equals(CategoryToCategory, StringComparison.OrdinalIgnoreCase)) { sourceComponent.ChildrenCategoryEntitiesList = UpdateHierarchy(arg, catalogItemBase.Id, sourceComponent.ChildrenCategoryEntitiesList, sourceChanged); catalogItemBaseComponent.ParentCategoryEntitiesList = UpdateHierarchy(arg, source.Id, catalogItemBaseComponent.ParentCategoryEntitiesList, changed); catalogItemBaseComponent.ParentCatalogEntitiesList = UpdateHierarchy(arg, ExtractCatalogId(source.Id), catalogItemBaseComponent.ParentCatalogEntitiesList, changed); } else if (arg.RelationshipType.Equals(CatalogToSellableItem, StringComparison.OrdinalIgnoreCase)) { sourceComponent.ChildrenSellableItemEntitiesList = UpdateHierarchy(arg, catalogItemBase.Id, sourceComponent.ChildrenSellableItemEntitiesList, sourceChanged); catalogItemBaseComponent.ParentCatalogEntitiesList = UpdateHierarchy(arg, source.Id, catalogItemBaseComponent.ParentCatalogEntitiesList, changed); } else if (arg.RelationshipType.Equals(CategoryToSellableItem, StringComparison.OrdinalIgnoreCase)) { sourceComponent.ChildrenSellableItemEntitiesList = UpdateHierarchy(arg, catalogItemBase.Id, sourceComponent.ChildrenSellableItemEntitiesList, sourceChanged); catalogItemBaseComponent.ParentCategoryEntitiesList = UpdateHierarchy(arg, source.Id, catalogItemBaseComponent.ParentCategoryEntitiesList, changed); catalogItemBaseComponent.ParentCatalogEntitiesList = UpdateHierarchy(arg, ExtractCatalogId(source.Id), catalogItemBaseComponent.ParentCatalogEntitiesList, changed); } if (changed.Value) { PersistEntityArgument persistEntityArgument = await _persistEntityPipeline.Run(new PersistEntityArgument(catalogItemBase), context); } } } if (sourceChanged.Value) { await _persistEntityPipeline.Run(new PersistEntityArgument(source), context); } return(arg); }