diff --git a/CommonAssemblyInfo.cs b/CommonAssemblyInfo.cs index 5a2d408d..0205145f 100644 --- a/CommonAssemblyInfo.cs +++ b/CommonAssemblyInfo.cs @@ -15,8 +15,8 @@ [assembly: AssemblyProduct("Virto Commerce Order Module")] [assembly: AssemblyCopyright("Copyright © VirtoCommerce 2011-2018")] -[assembly: AssemblyFileVersion("2.17.14.0")] -[assembly: AssemblyVersion("2.17.14.0")] +[assembly: AssemblyFileVersion("2.17.15.0")] +[assembly: AssemblyVersion("2.17.15.0")] #if DEBUG [assembly: AssemblyConfiguration("Debug")] diff --git a/VirtoCommerce.OrderModule.Data/Repositories/OrderRepositoryImpl.cs b/VirtoCommerce.OrderModule.Data/Repositories/OrderRepositoryImpl.cs index 1b8a614a..bad416b9 100644 --- a/VirtoCommerce.OrderModule.Data/Repositories/OrderRepositoryImpl.cs +++ b/VirtoCommerce.OrderModule.Data/Repositories/OrderRepositoryImpl.cs @@ -1,4 +1,4 @@ -using System.Data.Common; +using System.Data.Common; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; using System.Linq; @@ -210,6 +210,10 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder) public IQueryable CustomerOrders => GetAsQueryable(); public IQueryable Shipments => GetAsQueryable(); + public IQueryable ShipmentPackagesPackages => GetAsQueryable(); + public IQueryable ShipmentItems => GetAsQueryable(); + public IQueryable Discounts => GetAsQueryable(); + public IQueryable TaxDetails => GetAsQueryable(); public IQueryable InPayments => GetAsQueryable(); public IQueryable Addresses => GetAsQueryable(); public IQueryable LineItems => GetAsQueryable(); @@ -217,9 +221,9 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder) public virtual CustomerOrderEntity[] GetCustomerOrdersByIds(string[] ids, CustomerOrderResponseGroup responseGroup) { - var query = CustomerOrders.Where(x => ids.Contains(x.Id)) - .Include(x => x.Discounts) - .Include(x => x.TaxDetails); + var result = CustomerOrders.Where(x => ids.Contains(x.Id)).ToArray(); + var orderDiscounts = Discounts.Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); + var orderTaxDetails = TaxDetails.Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); if ((responseGroup & CustomerOrderResponseGroup.WithAddresses) == CustomerOrderResponseGroup.WithAddresses) { @@ -228,34 +232,34 @@ public virtual CustomerOrderEntity[] GetCustomerOrdersByIds(string[] ids, Custom if ((responseGroup & CustomerOrderResponseGroup.WithInPayments) == CustomerOrderResponseGroup.WithInPayments) { - var inPayments = InPayments.Include(x => x.TaxDetails) - .Include(x => x.Discounts) - .Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); + var inPayments = InPayments.Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); var paymentsIds = inPayments.Select(x => x.Id).ToArray(); + var paymentDiscounts = Discounts.Where(x => paymentsIds.Contains(x.PaymentInId)).ToArray(); + var paymentTaxDetails = TaxDetails.Where(x => paymentsIds.Contains(x.PaymentInId)).ToArray(); var paymentAddresses = Addresses.Where(x => paymentsIds.Contains(x.PaymentInId)).ToArray(); var transactions = Transactions.Where(x => paymentsIds.Contains(x.PaymentInId)).ToArray(); } if ((responseGroup & CustomerOrderResponseGroup.WithItems) == CustomerOrderResponseGroup.WithItems) { - var lineItems = LineItems.Include(x => x.TaxDetails) - .Include(x => x.Discounts) - .Where(x => ids.Contains(x.CustomerOrderId)) + var lineItems = LineItems.Where(x => ids.Contains(x.CustomerOrderId)) .OrderByDescending(x => x.CreatedDate).ToArray(); + var lineItemIds = lineItems.Select(x => x.Id).ToArray(); + var lineItemDiscounts = Discounts.Where(x => lineItemIds.Contains(x.LineItemId)).ToArray(); + var lineItemTaxDetails = TaxDetails.Where(x => lineItemIds.Contains(x.LineItemId)).ToArray(); } if ((responseGroup & CustomerOrderResponseGroup.WithShipments) == CustomerOrderResponseGroup.WithShipments) { - var shipments = Shipments.Include(x => x.TaxDetails) - .Include(x => x.Discounts) - .Include(x => x.Items) - .Include(x => x.Packages.Select(y => y.Items)) - .Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); + var shipments = Shipments.Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); var shipmentIds = shipments.Select(x => x.Id).ToArray(); + var shipmentDiscounts = Discounts.Where(x => shipmentIds.Contains(x.ShipmentId)).ToArray(); + var shipmentTaxDetails = TaxDetails.Where(x => shipmentIds.Contains(x.ShipmentId)).ToArray(); var addresses = Addresses.Where(x => shipmentIds.Contains(x.ShipmentId)).ToArray(); + var shipmentItems = ShipmentItems.Where(x => shipmentIds.Contains(x.ShipmentId)).ToArray(); + var packages = ShipmentPackagesPackages.Include(x => x.Items).Where(x => shipmentIds.Contains(x.ShipmentId)).ToArray(); } - - return query.ToArray(); + return result; } public virtual void RemoveOrdersByIds(string[] ids) diff --git a/VirtoCommerce.OrderModule.Data/Services/CustomerOrderBuilderImpl.cs b/VirtoCommerce.OrderModule.Data/Services/CustomerOrderBuilderImpl.cs index 17316e26..c701cb33 100644 --- a/VirtoCommerce.OrderModule.Data/Services/CustomerOrderBuilderImpl.cs +++ b/VirtoCommerce.OrderModule.Data/Services/CustomerOrderBuilderImpl.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using VirtoCommerce.Domain.Commerce.Model; @@ -25,9 +25,6 @@ public virtual orderModel.CustomerOrder PlaceCustomerOrderFromCart(cartModel.Sho { var customerOrder = ConvertCartToOrder(cart); _customerOrderService.SaveChanges(new[] { customerOrder }); - - customerOrder = _customerOrderService.GetByIds(new[] { customerOrder.Id }).FirstOrDefault(); - return customerOrder; } diff --git a/VirtoCommerce.OrderModule.Data/Services/CustomerOrderServiceImpl.cs b/VirtoCommerce.OrderModule.Data/Services/CustomerOrderServiceImpl.cs index ed0dc68b..c9d0b489 100644 --- a/VirtoCommerce.OrderModule.Data/Services/CustomerOrderServiceImpl.cs +++ b/VirtoCommerce.OrderModule.Data/Services/CustomerOrderServiceImpl.cs @@ -63,6 +63,7 @@ public virtual void SaveChanges(CustomerOrder[] orders) foreach (var order in orders) { EnsureThatAllOperationsHaveNumber(order); + LoadOrderDependencies(order); var originalEntity = dataExistOrders.FirstOrDefault(x => x.Id == order.Id); //Calculate order totals @@ -82,7 +83,6 @@ public virtual void SaveChanges(CustomerOrder[] orders) changedEntries.Add(new GenericChangedEntry(order, EntryState.Added)); } } - //Raise domain events EventPublisher.Publish(new OrderChangeEvent(changedEntries)); CommitChanges(repository); @@ -114,31 +114,13 @@ public virtual CustomerOrder[] GetByIds(string[] orderIds, string responseGroup if (customerOrder != null) { customerOrder = orderEntity.ToModel(customerOrder) as CustomerOrder; - if (customerOrder != null) - { - var shippingMethods = ShippingMethodsService.GetAllShippingMethods(); - if (!shippingMethods.IsNullOrEmpty()) - { - foreach (var shipment in customerOrder.Shipments) - { - shipment.ShippingMethod = shippingMethods.FirstOrDefault(x => x.Code.EqualsInvariant(shipment.ShipmentMethodCode)); - } - } - - var paymentMethods = PaymentMethodsService.GetAllPaymentMethods(); - if (!paymentMethods.IsNullOrEmpty()) - { - foreach (var payment in customerOrder.InPayments) - { - payment.PaymentMethod = paymentMethods.FirstOrDefault(x => x.Code.EqualsInvariant(payment.GatewayCode)); - } - } - } + //Calculate totals only for full responseGroup if (orderResponseGroup == CustomerOrderResponseGroup.Full) { TotalsCalculator.CalculateTotals(customerOrder); } + LoadOrderDependencies(customerOrder); retVal.Add(customerOrder); } } @@ -269,6 +251,29 @@ protected virtual Expression> GetKeywordPredicat return order => order.Number.Contains(criteria.Keyword) || order.CustomerName.Contains(criteria.Keyword); } + protected virtual void LoadOrderDependencies(CustomerOrder order) + { + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + var shippingMethods = ShippingMethodsService.GetAllShippingMethods(); + if (!shippingMethods.IsNullOrEmpty()) + { + foreach (var shipment in order.Shipments) + { + shipment.ShippingMethod = shippingMethods.FirstOrDefault(x => x.Code.EqualsInvariant(shipment.ShipmentMethodCode)); + } + } + var paymentMethods = PaymentMethodsService.GetAllPaymentMethods(); + if (!paymentMethods.IsNullOrEmpty()) + { + foreach (var payment in order.InPayments) + { + payment.PaymentMethod = paymentMethods.FirstOrDefault(x => x.Code.EqualsInvariant(payment.GatewayCode)); + } + } + } protected virtual void EnsureThatAllOperationsHaveNumber(CustomerOrder order) { var store = StoreService.GetById(order.StoreId); diff --git a/VirtoCommerce.OrderModule.Web/module.manifest b/VirtoCommerce.OrderModule.Web/module.manifest index 1124b03b..4e996b40 100644 --- a/VirtoCommerce.OrderModule.Web/module.manifest +++ b/VirtoCommerce.OrderModule.Web/module.manifest @@ -1,7 +1,7 @@ VirtoCommerce.Orders - 2.17.14 + 2.17.15 2.13.24