Skip to content

Instantly share code, notes, and snippets.

@simple17
Created January 10, 2020 08:56
Show Gist options
  • Save simple17/1b2c63de9d6931159ebdb5306cb5494b to your computer and use it in GitHub Desktop.
Save simple17/1b2c63de9d6931159ebdb5306cb5494b to your computer and use it in GitHub Desktop.
[rename cart] #episerver #commerce
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