November Happy Hour will be moved to Thursday December 5th.

OrderGroupFactory calculates shipping IDs incorrectly after upgrade

Found in

EPiServer.Commerce 13.26.0

Fixed in

EPiServer.Commerce 13.27.0

(Or a related package)

Created

Nov 23, 2020

Updated

Dec 21, 2020

State

Closed, Fixed and tested


Description

Fixed issue where OrderGroupFactory calculates shipping IDs incorrectly after upgrade.

For the multiple order forms in cart as the below code, the CreateShipment() are returning same ShipmentId (-2). See comments in code.

Code to reproduce:
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var orderGroupFactory = ServiceLocator.Current.GetInstance<IOrderGroupFactory>();
var currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>();
ICart cart = orderRepository.LoadOrCreateCart<ICart>(CustomerContext.Current.CurrentContactId, "Default", currentMarket);
if (cart != null)

{ orderRepository.Delete(cart.OrderLink); }

cart = orderRepository.LoadOrCreateCart<ICart>(CustomerContext.Current.CurrentContactId, "Default", currentMarket);
cart.GetFirstForm().Shipments.Clear();
cart.GetFirstForm().Shipments.Add(orderGroupFactory.CreateShipment(cart)); // Expected shipmentId is -2, which it is
orderRepository.Save(cart);
cart = orderRepository.LoadOrCreateCart<ICart>(CustomerContext.Current.CurrentContactId, "Default", currentMarket);
cart.GetFirstForm().Shipments.Add(orderGroupFactory.CreateShipment(cart));
//Expected shipmentId is -3 which it is in 13.18.2, but in 13.26.0 this is assigned -2 which leaves us with two shipments with the same id
cart.GetFirstForm().Shipments.Add(orderGroupFactory.CreateShipment(cart));
// This shipment gets id -3 which is fine