I am new to EPi server Commerce and I am trying to get the cart working. I have had a look at the 'Quicksilver' project and I'm using it as a reference.
I am at the stage where I can put VariationContent into the Cart by creating LineItems and adding them to the Cart by cart.AddLineItem(). But when I am trying to manipulate the cart, e.g. get a handle on a LineItem to update the quantity or removing it from the cart I can't get it working.
I can't figure out where the LineItems are stored..
var shipment = cart.GetFirstForm().Shipments.First(); //Gives me a shipment object with 0 LineItems var items = cart.GetAllLineItems(); //Gives me 0 LineItems var lineItem = items.FirstOrDefault(x => x.Code == code); //lineItem is NULL
Any pointers or information is highly appreciated.
Welcome to the best eCommerce framework ever :)
After you add the lineitem to cart, did you save the cart itself? Something like IOrderRepository.Save(cart)? Otherwise the changes made to the cart will be lost next time you load it up.
Thanks for the reply!
Yes, I do OrderRepository.Service.Save(Cart); after I added the LineItem, I can see the cart in commerce manager interface, and all the lineitems in it.
But you might be on to something, it doesent seem that it is stored in the Cart object...
As I mentioned, I have used the 'Quicksilver' project as a base for what I am doing, and I have compared to the code found there, but somehow I am missing something...
Just to make sure, did you cache the cart somehow? I mean you can load cart in Index action, then use it in AddToCart action, and then again in DeleteItem action, which still is the cart before adding items. What do you have if you call OrderRepository.Service.Load<ICart>() before deleting items?
Other node, as you are using OrderRepository.Service, I suspect it's Injected<IOrderRepository>. As you are using Quicksilver as a base, you can simply use constructor dependencies instead, which is a generally better way.
As far as I can see it's the same carte passed from the controller to my CartService class. However, some thing I believe is strange is when do the following
var tmp = _orderRepository.Service.Load<ICart>();
As oposed to
_cart = _cartService.Service.LoadOrCreateCart(_cartService.Service.DefaultCartName);
I get two carts, with different ID's
I haven't cached the cart purposly, I am not sure if there is any other code for caching that might interfere..
Yes, I am using Injected<IOrderReposotory>
I just wanted to update this thread and say that the issue I had were due to an programming error on my part.
Thanks for all the help