Skip to content

Commit

Permalink
fix: Check vendors from selected cart items for shipments and payments (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyshibanov authored Nov 13, 2023
1 parent 58ab379 commit 1926ba8
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ public virtual async Task<CustomerOrder> PlaceCustomerOrderFromCartAsync(Shoppin
protected virtual CustomerOrder ConvertCartToOrder(ShoppingCart cart)
{
var cartLineItemsMap = new Dictionary<string, LineItem>();
var vendorIds = new List<string>();

// Copy Native Properties
var order = ToOrderModel(cart);

// Copy LineItems
if (cart.Items != null)
{
order.Items = ToOrderModel(cart.Items.Where(x => x.SelectedForCheckout).ToList(), cartLineItemsMap);
var cartLineItems = cart.Items.Where(x => x.SelectedForCheckout).ToArray();
order.Items = ToOrderModel(cartLineItems, cartLineItemsMap);
vendorIds.AddRange(cartLineItems.Select(x => x.VendorId).Where(x => !string.IsNullOrEmpty(x)).Distinct());
}

// Copy Discounts
Expand All @@ -67,13 +70,19 @@ protected virtual CustomerOrder ConvertCartToOrder(ShoppingCart cart)
// Copy Shipments
if (cart.Shipments != null)
{
order.Shipments = ToOrderModel(cart.Shipments, cartLineItemsMap);
var cartShipments = vendorIds.Any()
? cart.Shipments.Where(x => string.IsNullOrEmpty(x.VendorId) || vendorIds.Contains(x.VendorId)).ToArray()
: cart.Shipments;
order.Shipments = ToOrderModel(cartShipments, cartLineItemsMap);
}

// Copy Payments
if (cart.Payments != null)
{
order.InPayments = ToOrderModel(cart, cart.Payments);
var cartPayments = vendorIds.Any()
? cart.Payments.Where(x => string.IsNullOrEmpty(x.VendorId) || vendorIds.Contains(x.VendorId)).ToArray()
: cart.Payments;
order.InPayments = ToOrderModel(cart, cartPayments);
}

// Copy DynamicProperties
Expand Down

0 comments on commit 1926ba8

Please sign in to comment.