Developer forum

Forum » Ecommerce - Standard features » Delete product from cart

Delete product from cart

Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

How can you delete a product from the cart just by product number, when yo udont have the ordreline.
Example, we would like to add a remove button on the product page if the product already is in cart we want to be able to remove it.
But we do not know the orderline, just the product number. Are there ways (without having to go through API) to remove the product?


Replies

 
Nicolai Pedersen
Reply

Hi Martin

You cannot - the same product number could be on multiple orderlines.

But in your list of products you can lookup the orderline id relatively simple in Razor:

var orderlineId = Dynamicweb.Ecommerce.Common.Context.Cart?.ProductOrderLines?.Where(ol => ol.ProductNumber == "1").FirstOrDefault()?.Id;

Replace "1" with the product number you are currently rendering. Remember to test performance. You might want to hold the ProductOrderLines collection in a variable.

BR Nicolai

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Thanks. I will test this.

In our case we would actually like to delete all instances of the product, even if it is distributed on several order lines, so that wouldnt have been an issue.

 

You must be logged in to post in the forum