Try our conversational search powered by Generative AI!

Episerver 10: Adding same SKU to the cart as different lineitems fails

Vote:
 

We need to add same SKU to cart as different lienitems. This happens when there is a item with personalized information. A customer can add 1 item with personalization values and another with a different personalization value. In this situation the same SKU needs to be added twice to the cart as individual lineitem. This fails. 

var orderService = ServiceLocator.Current.GetInstance();
orderService.Save(cart);

Is there a way to customize the IOrderRepository.Save(cart) method? Which Dll can have its detailed implementation?

#178141
May 02, 2017 21:08
Vote:
 

Hi, Sapna

You could add a new lineItem with same SKU and also add some personal value into that. Those codes below is example:

var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var cart = orderRepository.LoadOrCreateCart<ICart>(customerId, "Default");

var lineItem = cart.CreateLineItem(entryCode);
lineItem.Quantity = 1;
lineItem.PlacedPrice = 100;
lineItem.Properties["personalValue"] = "customValue ... ";

var shipment = cart.GetFirstShipment();
shipment.LineItems.Add(lineItem);

orderRepository.Save(cart);

And you could repeat this with the same entry code to add more lineitem.

var cart = orderRepository.LoadOrCreateCart<ICart>(customerId, "Default");

var lineItem = cart.CreateLineItem(entryCode);
lineItem.Quantity = 1;
lineItem.PlacedPrice = 100;
lineItem.Properties["personalValue"] = "other value ... ";

var shipment = cart.GetFirstShipment();
shipment.LineItems.Add(lineItem);

orderRepository.Save(cart);

Hope this helps,

/Son Do

#178144
May 03, 2017 8:15
Vote:
 

Whoohooo!!!! That worked like a charm. Thak you!

#178182
May 03, 2017 17:57
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.