Skip to content

Commit

Permalink
2.17.15
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarincev committed Jun 24, 2018
1 parent 55fcccd commit fa06767
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
38 changes: 21 additions & 17 deletions VirtoCommerce.OrderModule.Data/Repositories/OrderRepositoryImpl.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -210,16 +210,20 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)

public IQueryable<CustomerOrderEntity> CustomerOrders => GetAsQueryable<CustomerOrderEntity>();
public IQueryable<ShipmentEntity> Shipments => GetAsQueryable<ShipmentEntity>();
public IQueryable<ShipmentPackageEntity> ShipmentPackagesPackages => GetAsQueryable<ShipmentPackageEntity>();
public IQueryable<ShipmentItemEntity> ShipmentItems => GetAsQueryable<ShipmentItemEntity>();
public IQueryable<DiscountEntity> Discounts => GetAsQueryable<DiscountEntity>();
public IQueryable<TaxDetailEntity> TaxDetails => GetAsQueryable<TaxDetailEntity>();
public IQueryable<PaymentInEntity> InPayments => GetAsQueryable<PaymentInEntity>();
public IQueryable<AddressEntity> Addresses => GetAsQueryable<AddressEntity>();
public IQueryable<LineItemEntity> LineItems => GetAsQueryable<LineItemEntity>();
public IQueryable<PaymentGatewayTransactionEntity> Transactions => GetAsQueryable<PaymentGatewayTransactionEntity>();

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)
{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using VirtoCommerce.Domain.Commerce.Model;
Expand All @@ -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();

This comment has been minimized.

Copy link
@benb1n

benb1n Jun 24, 2018

Contributor

@tatarincev If I remember correctly, this call to retrieve the order again may be necessary since OrderChangedHandlers may have updated the order during the event that happens inside of _customerOrderService.SaveChanges(). I know that we have a handler that does that for new orders.

This comment has been minimized.

Copy link
@tatarincev

tatarincev Jun 24, 2018

Author Contributor

Yes, but inside your handler you do a changes on the this order instance, and order reload not required and redundant here.

This comment has been minimized.

Copy link
@benb1n

benb1n Jun 24, 2018

Contributor

Ok, that makes sense.


return customerOrder;
}

Expand Down
47 changes: 26 additions & 21 deletions VirtoCommerce.OrderModule.Data/Services/CustomerOrderServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,7 +83,6 @@ public virtual void SaveChanges(CustomerOrder[] orders)
changedEntries.Add(new GenericChangedEntry<CustomerOrder>(order, EntryState.Added));
}
}

//Raise domain events
EventPublisher.Publish(new OrderChangeEvent(changedEntries));
CommitChanges(repository);
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -269,6 +251,29 @@ protected virtual Expression<Func<CustomerOrderEntity, bool>> 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);
Expand Down
2 changes: 1 addition & 1 deletion VirtoCommerce.OrderModule.Web/module.manifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<module>
<id>VirtoCommerce.Orders</id>
<version>2.17.14</version>
<version>2.17.15</version>
<platformVersion>2.13.24</platformVersion>
<dependencies>
<dependency id="VirtoCommerce.Core" version="2.25.1" />
Expand Down

0 comments on commit fa06767

Please sign in to comment.