Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Creating order returns wrong market?

Vote:
 

Hi

We have a customer with a strange bug where the cart replaces market and settings once we save the cart in the IOrderRepository.

We try to save Finnish context but end up saving a Swedish context based cart instead.

The following snippet is where we somehow end up picking up the wrong context, but the question is why?

 ICart cart = cart.GetOrCreateCart(); // here is Finnish context

 // Order is valid, create on hold cart in epi
   cart.Name = OrderStatus.OnHold.ToString();
  _orderRepository.Save(cart); // here is Finnish context

  // Create new default cart
var newCart = _orderRepository.Create<ICart>(cart.CustomerId, Cart.DefaultName);
_orderRepository.Save(newCart); // here is all of sudden Swedish context

When we try call the Save method we also receive the following error message:

Mediachase.Commerce.Orders.Exceptions.OrderException: A cart with same CustomerId, Name, and MarketId already exist. Creating duplicated cart is not allowed
   at EPiServer.Commerce.Order.Internal.DataAccess.SerializableCartDB.Save(SerializableCart cart)
   at EPiServer.Commerce.Order.Internal.SerializableCartProvider.Save(ICart cart)
   at EPiServer.Commerce.Order.Internal.DefaultOrderRepository.Save(IOrderGroup order)

We are running EPiServer.Commerce.13.32.1

I am quite new to the commerce installation of Episerver, hence might have some setting or imagination of the context wrong here

#280829
May 24, 2022 8:10
Vote:
 

var newCart = _orderRepository.Create<ICart>(cart.CustomerId, Cart.DefaultName);

This will create a cart with the current market. If you have a custom implementation of ICurrentMarket (which you most likely do), you might want to take a look. Alternatively, you can call SetCurrentMarket(MarketId marketId) before to make sure you are in the right market

#280830
May 24, 2022 10:09
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.