Try our conversational search powered by Generative AI!

Cannot update line items quantity in cart


LineItem quantity will not save, what do i do? 

private List IncreaseOrDecreaseQuantity(string productCode, bool decrease)
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = _orderRepository.LoadOrCreateCart(contactId, "Default");

var currentCartItems = GetCartItems();
var lineItem = currentCartItems.FirstOrDefault(x => x.Code.Equals(productCode));

var value = decrease ? -1 : 1;

if (lineItem != null)
cart.UpdateLineItemQuantity(cart.GetFirstShipment(), lineItem, lineItem.Quantity + value);


var a = cart.GetAllLineItems();
return currentCartItems;

_orderRepository = IOrderRepository

Jan 31, 2018 16:13

You can simply set the Quantity property of the LineItem instance to the desired value. I have to check the code to be sure but I think UpdateLineItemQuantity actually check and set the Quantity based on availability 

Feb 01, 2018 2:48

I think UpdateLineItemQuantity updates the quantity, but _orderRepository does not save it.

Feb 01, 2018 9:35

Nevermind, if someone suddenly gets this issue, my solution was to not convert ILineItem to LineItem. UpdateLineItemQuantity works with ILineItem, not LineItem..

Feb 01, 2018 10:35

Actually that's not true. UpdateLineItemQuantity works with both. I checked the code now and it checks if the shipment is Shipment or not and does change the quanitty accordingly. I don't now what you have in GetCartItems, but it supposedly returns a list of LineItem. You can use cart.GetAllLineItems to return a list of ILineItem, and update the quantity directly, without having to call UpdateLineItemQuantity. A rule of thumb is to use the abstraction APIs all the way, not to mix it with the concrete classes.

Feb 02, 2018 12:38
* 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.