/// <summary> /// Removes many line items from the cart at once. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual Task <ProcessedCart> RemoveLineItemsAsync(RemoveLineItemsParam param) { if (param == null) { throw new ArgumentNullException("param"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Scope"), "param"); } if (String.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CartName"), "param"); } if (param.CultureInfo == null) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CultureInfo"), "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CustomerId"), "param"); } if (param.LineItems == null) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("LineItems"), "param"); } if (param.LineItems.Any(li => li.Id == Guid.Empty)) { throw new ArgumentException("LineItems may not contain an empty Guid for Id", "param"); } if (param.LineItems.Any(li => String.IsNullOrWhiteSpace(li.ProductId))) { throw new ArgumentException("LineItems may not contain an empty string for ProductId", "param"); } var request = new AddOrUpdateLineItemsRequest { CartName = param.CartName, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope, LineItems = param.LineItems.Select(li => new LineItemInfo { Id = li.Id, ProductId = li.ProductId, VariantId = li.VariantId, Quantity = 0.0, RecurringOrderFrequencyName = string.Empty, RecurringOrderProgramName = string.Empty, }).ToList() }; var cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
/// <summary> /// Add one or more line items to a cart. /// In case cart does not exist - it will be created. /// If a product or a variant already exists in a cart, it will be merged with adding ones. /// </summary> /// <param name="param">Parameters to be used for adding</param> /// <returns>Processed cart</returns> public virtual Task <ProcessedCart> AddLineItemsAsync(AddLineItemsParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.LineItems == null || param.LineItems.Count == 0) { throw new ArgumentException(GetMessageOfNullEmpty(nameof(param.LineItems)), nameof(param)); } AddOrUpdateLineItemsRequest request = new AddOrUpdateLineItemsRequest { CartName = param.CartName, CartType = param.CartType, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, LineItems = param.LineItems, ScopeId = param.Scope }; CacheKey cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
/// <summary> /// Removes many line items from the cart at once. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual Task <ProcessedCart> RemoveLineItemsAsync(RemoveLineItemsParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.LineItems == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.LineItems)), nameof(param)); } var list = new List <LineItemInfo>(); for (int i = 0; i < param.LineItems.Count; i++) { var currentLine = param.LineItems[i]; if (currentLine.Id == Guid.Empty) { throw new InvalidOperationException($"Line item with index {i} has empty id"); } else if (string.IsNullOrWhiteSpace(currentLine.ProductId)) { throw new InvalidOperationException($"Line item with index {i} has null or white space product id"); } list.Add(new LineItemInfo { Id = currentLine.Id, ProductId = currentLine.ProductId, VariantId = currentLine.VariantId, Quantity = 0.0, RecurringOrderFrequencyName = string.Empty, RecurringOrderProgramName = string.Empty, }); } //Removing method, but AddOrUpdate request, it is unclear var request = new AddOrUpdateLineItemsRequest { CartName = param.CartName, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope, LineItems = list }; var cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }