Created
January 10, 2020 08:56
-
-
Save simple17/1b2c63de9d6931159ebdb5306cb5494b to your computer and use it in GitHub Desktop.
[rename cart] #episerver #commerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool RenameListForAccount(Guid accountId, string oldName, string newName) | |
{ | |
var cart = _orderRepository.Load<ICart>(accountId, oldName).FirstOrDefault(); | |
if (_orderRepository.Load<ICart>(accountId, newName).Any() || (cart is null)) | |
{ | |
Log.Error($"Cannot rename list for account {accountId} with name {newName} because a cart with this name already exists for this account"); | |
return false; | |
} | |
var newCart = _orderRepository.Create<ICart>(cart.CustomerId, newName); | |
newCart.MarketId = cart.MarketId; | |
newCart.CopyFrom(cart, _orderGroupFactory); | |
_orderRepository.Save(newCart); | |
var prevCartOrderLink = cart.OrderLink; | |
_orderRepository.Delete(prevCartOrderLink); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment