Try our conversational search powered by Generative AI!

Issue with IShipment.LineItems.Remove method



According to the documentation you can remove line items from a shipment uisng the Remove method:


In my case that is not working. 

Let's say I have an order that consists of 4 items of product Y, and I want to remove 2 of them. 

What happens is that only 1 gets removed. 

Note: In our site we have our line items in a flat structure, this means that for the example order we will have 4 line items for same sku with qantity 1.

I would consider this a bug, do you agree?

What I would like to see in the api is a method like this:


Nov 30, 2016 9:11


That's pretty strange. Can you provide a test case to reproduce the bug? We will work on it ASAP.



Nov 30, 2016 9:24
  • Create a cart with 4 line items of same sku (same code) with quantity 1
  • Save the cart as a purchase order
  • In the complete shipment event (setting order to Complete), remove 2 of the line items
  • Go to commerce manager and see that only 1 is removed

The code for adding items to the cart is using the old api:


Note: the flag 'LineItemRollup" is set to false.

Edited, Nov 30, 2016 9:32
<p>I am also able to reproduce this in&nbsp;QuickSilver.</p>
Nov 30, 2016 12:41

Wait ... what... You added the items using old APIs and removed them by the new APIs? No candies for you!

I will try to verify this issue and file a bug when I have time.



Dec 01, 2016 9:43

Haha, we're slowly moving our code over to the new api, but that is a process that takes time ;) Thanks!

Dec 01, 2016 9:45

Btw: Adding and removing items in QuickSilver using new api result in the same error ;)

Dec 01, 2016 9:50

Hi Mari,

You're using old api to add lineitem to OrderForm, so could you try using old api to remove lineitem


Or you could use new api to add lineitem to shipment or remove lineitem from shipment as document you mentioned

var lineItem = orderFactory.CreateLineItem("code");
var shipment = GetFirstShipment();
cart.AddLineItem(shipment, lineItem); 

Edited, Dec 01, 2016 9:52
<p>Son Do: the bug exists in new api as well.</p>
Dec 01, 2016 9:53

Could you show your code? Or step to reproduce on Quicksilver, we will verify easier.

Dec 01, 2016 9:58

Sample code to reproduce in QuickSilver (using an existing order). First, add 4 line items of same sku:

var orderRepo = ServiceLocator.Current.GetInstance<IOrderRepository>();
            var orderFactory = ServiceLocator.Current.GetInstance<IOrderFactory>();
            var orderId = 9;

            var order = orderRepo.Load<IPurchaseOrder>(orderId);
            var form = order.GetFirstForm();
            var shipment = form.Shipments.First();

            var lineItemOne = orderFactory.CreateLineItem("SKU-21320033");
            lineItemOne.Quantity = 1;
            var lineItemTwo = orderFactory.CreateLineItem("SKU-21320033");
            lineItemTwo.Quantity = 1;
            var lineItemThree = orderFactory.CreateLineItem("SKU-21320033");
            lineItemThree.Quantity = 1;
            var lineItemFour = orderFactory.CreateLineItem("SKU-21320033");
            lineItemFour.Quantity = 1;



Next, we try to remove 2 of them:

 var orderRepo = ServiceLocator.Current.GetInstance<IOrderRepository>();
            var orderId = 9;

            var order = orderRepo.Load<IPurchaseOrder>(orderId);
            var form = order.GetFirstForm();
            var shipment = form.Shipments.First();

            var lineItemsToRemove = shipment.LineItems.Where(l => l.Code == "SKU-21320033").Take(2).ToList();

            foreach (var lineItem in lineItemsToRemove)


Result: Instead of removing 2 items, only 1 is removed. If you try to remove 4, same result: only 1 is removed.

Dec 01, 2016 12:39

I created a bug for it - will keep you posted when we investigate. Thanks for bringing this into our attention.


Dec 01, 2016 15:13

Thanks, Quan!

Dec 02, 2016 9:10

Hi there,

We got this issue before when try to remove line item from the shipment too. It looks similar issue you have.

You can change the code remove line item like that

foreach (var lineItem in giftItems)
   shipment.LineItems.Remove(shipment.LineItems.FirstOrDefault(l => l.LineItemId == lineItem.LineItemId));

Hope that fix your issue!


Dec 02, 2016 11:27

Tuan, yes that will work as a temporary workaround until Episerver fixes the bug. Thanks!

Dec 02, 2016 11:34
* 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.