/// <summary> /// Retrieve a cart /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public virtual async Task <CartViewModel> GetCartViewModelAsync(GetCartParam param) { if (param == null) { throw new ArgumentNullException(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 (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } ProcessedCart cart; try { cart = await CartRepository.GetCartAsync(param).ConfigureAwait(false); } catch (ComposerException ex) { ClearEditModeIfCartDraftDoesNotExist(param.CartType, ex); throw; } await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, CartType = param.CartType, CustomerId = param.CustomerId, Scope = param.Scope, CouponCodes = CouponViewService.GetInvalidCouponsCode(cart.Coupons).ToList() }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = false, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
/// <summary> /// Remove line item to the cart. /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public async virtual Task <CartViewModel> RemoveLineItemAsync(RemoveLineItemParam param) { if (param == null) { throw new ArgumentNullException("param", "param is required"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException("param.Scope is required", "param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo is required", "param"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (param.LineItemId == Guid.Empty) { throw new ArgumentException("param.LineItemId is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException("param.BaseUrl is required", "param"); } var cart = await CartRepository.RemoveLineItemAsync(param).ConfigureAwait(false); await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, CouponCodes = CouponViewService.GetInvalidCouponsCode(cart.Coupons).ToList(), CustomerId = param.CustomerId, Scope = param.Scope, }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = true, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
/// <summary> /// Update the Cart /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual async Task <CartViewModel> UpdateCartAsync(UpdateCartViewModelParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (param.Coupons == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.Coupons)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.Shipments == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.Shipments)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.BillingCurrency)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BillingCurrency)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartType)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartType)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Status)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Status)), nameof(param)); } var updatedCart = await CartRepository.UpdateCartAsync(param).ConfigureAwait(false); await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, CouponCodes = CouponViewService.GetInvalidCouponsCode(param.Coupons).ToList(), CustomerId = param.CustomerId, Scope = param.Scope }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = updatedCart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = true, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
public virtual async Task <CartViewModel> UpdateLineItemAsync(UpdateLineItemParam param) { if (!RecurringOrdersSettings.Enabled) { return(GetEmptyRecurringOrderCartViewModel()); } if (param == null) { throw new ArgumentNullException("param", "param is required"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (string.IsNullOrWhiteSpace(param.ScopeId)) { throw new ArgumentException("param.ScopeId is required", "param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo is required", "param"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (param.LineItemId == Guid.Empty) { throw new ArgumentException("param.LineItemId is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (param.Quantity < 1) { throw new ArgumentException("param.Quantity must be greater than 0", "param"); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException("param.BaseUrl is required", "param"); } var cart = await CartRepository.UpdateLineItemAsync(param).ConfigureAwait(false); await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, CouponCodes = CouponViewService.GetInvalidCouponsCode(cart.Coupons).ToList(), CustomerId = param.CustomerId, Scope = param.ScopeId }); var vmParam = new CreateRecurringOrderCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = true, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam); return(viewModel); }
/// <summary> /// Update a line item in the cart. /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public async virtual Task <CartViewModel> UpdateLineItemAsync(UpdateLineItemParam 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.ScopeId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ScopeId)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (param.LineItemId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.LineItemId)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.Quantity < 1) { throw new ArgumentOutOfRangeException(nameof(param), param.Quantity, GetMessageOfZeroNegative(nameof(param.Quantity))); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param)); } var cart = await CartRepository.UpdateLineItemAsync(param).ConfigureAwait(false); await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, CouponCodes = CouponViewService.GetInvalidCouponsCode(cart.Coupons).ToList(), CustomerId = param.CustomerId, Scope = param.ScopeId }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = true, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }