private void ValidateItems() { CatalogRelationDto relationDto = null; CatalogDto.CatalogRow catalogRow = null; var marketTester = new ExcludedCatalogEntryMarketsField(); var orderMarket = ServiceLocator.Current.GetInstance <IMarketService>().GetMarket(OrderGroup.MarketId); var orderForms = OrderGroup.OrderForms.ToArray(); var lineItems = orderForms.SelectMany(x => x.LineItems.ToArray()); var validLineItems = lineItems.Where(x => x.CatalogEntryId != "0" && !String.IsNullOrEmpty(x.CatalogEntryId) && !x.CatalogEntryId.StartsWith("@")); foreach (var lineItem in validLineItems) { var entryRow = GetEntryRowForLineItem(lineItem); if (entryRow == null) { AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id, String.Format("The catalog entry code that maps to the line item {0} has been removed or changed. The line item is no longer valid", lineItem.CatalogEntryId)); DeleteInvalidItem(orderForms, lineItem); continue; } if (!marketTester.IsValidForMarket(entryRow, orderMarket)) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because it is not available in your market.", lineItem.DisplayName)); DeleteInvalidItem(orderForms, lineItem); } else if (entryRow.IsActive && entryRow.StartDate < FrameworkContext.Current.CurrentDateTime && entryRow.EndDate > FrameworkContext.Current.CurrentDateTime) { if (catalogRow == null || catalogRow.CatalogId != entryRow.CatalogId) { var catalogDto = CatalogContext.Current.GetCatalogDto(entryRow.CatalogId); catalogRow = catalogDto.Catalog.FirstOrDefault(); } // check if catalog is visible if (catalogRow != null && catalogRow.IsActive && catalogRow.StartDate < FrameworkContext.Current.CurrentDateTime && catalogRow.EndDate > FrameworkContext.Current.CurrentDateTime) { relationDto = CatalogContext.Current.GetCatalogRelationDto(entryRow.CatalogEntryId); // populate item lineItem.Catalog = catalogRow.Name; lineItem.ParentCatalogEntryId = GetParentCatalogEntryId(entryRow.CatalogEntryId, relationDto); //Inventory Info IWarehouseInventory aggregateInventory = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>() .GetTotal(new CatalogKey(entryRow)); PopulateInventoryInfo(aggregateInventory, lineItem); //Variation Info PopulateVariationInfo(entryRow, lineItem); } } } }
private void ValidateItems() { CatalogRelationDto relationDto = null; CatalogDto.CatalogRow catalogRow = null; var marketTester = new ExcludedCatalogEntryMarketsField(); var orderMarket = ServiceLocator.Current.GetInstance<IMarketService>().GetMarket(OrderGroup.MarketId); var lineItems = OrderGroup.OrderForms.SelectMany(x => x.LineItems.ToArray()); var validLineItems = lineItems.Where(x => x.Code != "0" && !String.IsNullOrEmpty(x.Code) && !x.Code.StartsWith("@")); List<LineItem> lineItemsToRemoved = new List<LineItem>(); foreach (var lineItem in validLineItems) { var entryRow = GetEntryRowForLineItem(lineItem); if (entryRow == null) { AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id, String.Format("The catalog entry code that maps to the line item {0} has been removed or changed. The line item is no longer valid", lineItem.Code)); lineItemsToRemoved.Add(lineItem); continue; } if (!marketTester.IsValidForMarket(entryRow, orderMarket)) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because it is not available in your market.", lineItem.DisplayName)); lineItemsToRemoved.Add(lineItem); continue; } var requestDate = FrameworkContext.Current.CurrentDateTime; if (catalogRow == null || catalogRow.CatalogId != entryRow.CatalogId) { var catalogDto = CatalogContext.Current.GetCatalogDto(entryRow.CatalogId); catalogRow = catalogDto.Catalog.FirstOrDefault(); } //check if the catalog of this entry is not available if (catalogRow == null || !catalogRow.IsActive || requestDate < catalogRow.StartDate || requestDate > catalogRow.EndDate) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because the catalog of this entry is not available.", lineItem.DisplayName)); lineItemsToRemoved.Add(lineItem); continue; } relationDto = CatalogContext.Current.GetCatalogRelationDto(entryRow.CatalogEntryId); // populate item lineItem.Catalog = catalogRow.Name; lineItem.ParentCatalogEntryId = GetParentCatalogEntryId(entryRow.CatalogEntryId, relationDto); //Variation Info PopulateVariationInfo(entryRow, lineItem); if (string.IsNullOrEmpty(lineItem.WarehouseCode)) { // This case was passed because lineItem.WarehouseCode will be set in next activity - GetFulfillmentWarehouseActivity continue; } var inventoryRecord = InventoryService.Get(lineItem.Code, lineItem.WarehouseCode); if (inventoryRecord == null) { AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id, String.Format("The catalog entry code that maps to the line item {0} has been removed or changed. The line item is no longer valid", lineItem.Code)); lineItemsToRemoved.Add(lineItem); continue; } // Get minimum date that the entry is available. It should be is minimum date of preorder date and start date var minAvailableDate = entryRow.StartDate; if (inventoryRecord != null && inventoryRecord.PreorderAvailableUtc > SafeBeginningOfTime && minAvailableDate > inventoryRecord.PreorderAvailableUtc) { minAvailableDate = inventoryRecord.PreorderAvailableUtc; } //check if the entry is not available if (!entryRow.IsActive || requestDate < minAvailableDate || requestDate > entryRow.EndDate) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because it is not available.", lineItem.DisplayName)); lineItemsToRemoved.Add(lineItem); continue; } //Inventory Info PopulateInventoryInfo(inventoryRecord, lineItem); } if (lineItemsToRemoved.Count > 0) { // remove lineitem from shipment foreach (OrderForm form in OrderGroup.OrderForms) { foreach (var lineItem in lineItemsToRemoved) { form.RemoveLineItemFromShipments(lineItem); } } // remove lineitem from order foreach (var lineItem in lineItemsToRemoved) { lineItem.Delete(); } } }
private void ValidateItems() { CatalogRelationDto relationDto = null; CatalogDto.CatalogRow catalogRow = null; var marketTester = new ExcludedCatalogEntryMarketsField(); var orderMarket = ServiceLocator.Current.GetInstance <IMarketService>().GetMarket(OrderGroup.MarketId); var lineItems = OrderGroup.OrderForms.SelectMany(x => x.LineItems.ToArray()); var validLineItems = lineItems.Where(x => x.Code != "0" && !String.IsNullOrEmpty(x.Code) && !x.Code.StartsWith("@") && !x.IsGift); List <LineItem> lineItemsToRemove = new List <LineItem>(); foreach (var lineItem in validLineItems) { var entryRow = GetEntryRowForLineItem(lineItem); if (entryRow == null) { AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id, String.Format("The catalog entry code that maps to the line item {0} has been removed or changed. The line item is no longer valid", lineItem.Code)); continue; } if (!marketTester.IsValidForMarket(entryRow, orderMarket)) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because it is not available in your market.", lineItem.DisplayName)); lineItemsToRemove.Add(lineItem); continue; } var requestDate = FrameworkContext.Current.CurrentDateTime; if (catalogRow == null || catalogRow.CatalogId != entryRow.CatalogId) { var catalogDto = CatalogContext.Current.GetCatalogDto(entryRow.CatalogId); catalogRow = catalogDto.Catalog.FirstOrDefault(); } //check if the catalog of this entry is not available if (catalogRow == null || !catalogRow.IsActive || requestDate < catalogRow.StartDate || requestDate > catalogRow.EndDate) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because the catalog of this entry is not available.", lineItem.DisplayName)); lineItemsToRemove.Add(lineItem); continue; } relationDto = CatalogContext.Current.GetCatalogRelationDto(entryRow.CatalogEntryId); // populate item lineItem.Catalog = catalogRow.Name; lineItem.ParentCatalogEntryId = GetParentCatalogEntryId(entryRow.CatalogEntryId, relationDto); //Variation Info PopulateVariationInfo(entryRow, lineItem, lineItemsToRemove); if (string.IsNullOrEmpty(lineItem.WarehouseCode)) { // This case was passed because lineItem.WarehouseCode will be set in next activity - GetFulfillmentWarehouseActivity continue; } var inventoryRecord = InventoryService.Get(lineItem.Code, lineItem.WarehouseCode); if (inventoryRecord == null) { AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id, String.Format("The catalog entry code that maps to the line item {0} has been removed or changed. The line item is no longer valid", lineItem.Code)); lineItemsToRemove.Add(lineItem); continue; } // Get minimum date that the entry is available. It should be is minimum date of preorder date and start date var minAvailableDate = entryRow.StartDate; if (inventoryRecord != null && inventoryRecord.PreorderAvailableUtc > SafeBeginningOfTime && minAvailableDate > inventoryRecord.PreorderAvailableUtc) { minAvailableDate = inventoryRecord.PreorderAvailableUtc; } //check if the entry is not available if (!entryRow.IsActive || requestDate < minAvailableDate || requestDate > entryRow.EndDate) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because it is not available.", lineItem.DisplayName)); lineItemsToRemove.Add(lineItem); continue; } //Inventory Info PopulateInventoryInfo(inventoryRecord, lineItem); } if (lineItemsToRemove.Count > 0) { // remove lineitem from shipment foreach (OrderForm form in OrderGroup.OrderForms) { foreach (var lineItem in lineItemsToRemove) { form.RemoveLineItemFromShipments(lineItem); } } // remove lineitem from order foreach (var lineItem in lineItemsToRemove) { lineItem.Delete(); } } }
private void ValidateItems() { CatalogRelationDto relationDto = null; CatalogDto.CatalogRow catalogRow = null; var marketTester = new ExcludedCatalogEntryMarketsField(); var orderMarket = ServiceLocator.Current.GetInstance<IMarketService>().GetMarket(OrderGroup.MarketId); var orderForms = OrderGroup.OrderForms.ToArray(); var lineItems = orderForms.SelectMany(x => x.LineItems.ToArray()); var validLineItems = lineItems.Where(x => x.CatalogEntryId != "0" && !String.IsNullOrEmpty(x.CatalogEntryId) && !x.CatalogEntryId.StartsWith("@")); foreach (var lineItem in validLineItems) { var entryRow = GetEntryRowForLineItem(lineItem); if (entryRow == null) { AddWarningSafe(Warnings,"LineItemCodeRemoved-" + lineItem.Id, String.Format("The catalog entry code that maps to the line item {0} has been removed or changed. The line item is no longer valid", lineItem.CatalogEntryId)); DeleteInvalidItem(orderForms,lineItem); continue; } if (!marketTester.IsValidForMarket(entryRow, orderMarket)) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because it is not available in your market.", lineItem.DisplayName)); DeleteInvalidItem(orderForms, lineItem); } else if (entryRow.IsActive && entryRow.StartDate < FrameworkContext.Current.CurrentDateTime && entryRow.EndDate > FrameworkContext.Current.CurrentDateTime) { if (catalogRow == null || catalogRow.CatalogId != entryRow.CatalogId) { var catalogDto = CatalogContext.Current.GetCatalogDto(entryRow.CatalogId); catalogRow = catalogDto.Catalog.FirstOrDefault(); } // check if catalog is visible if (catalogRow != null && catalogRow.IsActive && catalogRow.StartDate < FrameworkContext.Current.CurrentDateTime && catalogRow.EndDate > FrameworkContext.Current.CurrentDateTime) { relationDto = CatalogContext.Current.GetCatalogRelationDto(entryRow.CatalogEntryId); // populate item lineItem.Catalog = catalogRow.Name; lineItem.ParentCatalogEntryId = GetParentCatalogEntryId(entryRow.CatalogEntryId, relationDto); //Inventory Info IWarehouseInventory aggregateInventory = ServiceLocator.Current.GetInstance<IWarehouseInventoryService>() .GetTotal(new CatalogKey(entryRow)); PopulateInventoryInfo(aggregateInventory, lineItem); //Variation Info PopulateVariationInfo(entryRow, lineItem); } } } }