Deleted variant still in cart? [12.8]

Vote:
 

Hi!

If I place a variant in my shopping cart and the delete the variant from the catalog the variant is still loaded into the cart.  Even if I restart everything the variant is still loaded.

This code gives me the deleted variant:

var lineItems = cart.GetAllLineItems();
var variantReferences = _referenceConverter.GetContentLinks(lineItems.Select(l => l.Code))
                .Select(c => c.Value).Where(c => !ContentReference.IsNullOrEmpty(c));
                    
var variants = _contentLoader.GetItems(variantReferences,_preferredCulture).OfType().ToList();

These validations are run:

cart.ValidateOrRemoveLineItems((item, issue) => issues.AddValidationIssues(item, issue), _lineItemValidator);
cart.UpdateInventoryOrRemoveLineItems((item, issue) => issues.AddValidationIssues(item, issue), _inventoryProcessor);
cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings());
cart.UpdateInventoryOrRemoveLineItems((item, issue) => { }, _inventoryProcessor);       

I get all information about the variant even though it is deleted, but I can't get an url to the item which I guess is how it is supposed to be.

Is this Episerver standard or maybe I'm missing something here?

/Kristoffer

#199317
Nov 22, 2018 15:17
Vote:
 

Did you save your cart after running validation? Because 

ValidateOrRemoveLineItems

should remove line items with variant deleted, however it does not save the cart 

#199326
Nov 22, 2018 15:57
Vote:
 

Ok, that might be it! And you only have to save it if there are any validation issues I guess?

#199331
Nov 22, 2018 17:47
Vote:
 

That was it! In one place I did a validation without saving the cart, thanks Quan!

#199333
Nov 22, 2018 19:26
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.