November Happy Hour will be moved to Thursday December 5th.

Copy content from 1 cart to another?

Vote:
 

I am trying to figure out what is the best way to copy content from cart A to a new cart B.
I have a requirement from the customer, that everytime a Dealer clicks Save.

The cart should be saved and a new cart, with new cart ID should be created but it should contain everything that the old cart contains.

So what is the best way to "clone" a cart in EPiCom 11?

 

#205048
Jun 27, 2019 8:49
Vote:
 

If you are using the old cart system with the legacy API, you can have this

newCart.Add(oldCart);

which copies everything to the new cart.

If you are using the new API there is no built in API to do that, but you can just add item by item

#205055
Jun 27, 2019 10:42
Vote:
 

Now the question is what 


How about

var newCart = _orderRepo.Create<ICart>(oldCart.CustomerId, oldCart.CartName);
newCart.MarketId = cart.MarketId;
newCart.CopyFrom(oldCart, _orderGroupFactory);
Save(newCart);






#205252
Jul 03, 2019 8:35
Quan Mai - Jul 03, 2019 12:41
That's very good finding. I was not aware that such method exists. Nice job

Note that MarketId is also copied in CopyFrom so you don't have to set it yourself
* 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.