protected virtual Task <ProcessedCart> FixWishList(ProcessedCart wishList) { return(FixCartService.SetFulfillmentLocationIfRequired(new FixCartParam { Cart = wishList })); }
/// <summary> /// Add line item to the cart. /// /// CartName will be created if needed /// CustomerId (guest customers) will be created if needed /// If the (product,variant) is already in the cart, the quantity will be increased; /// otherwise a new line will be added /// /// param.VariantId is optional /// /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public async virtual Task <CartViewModel> AddLineItemAsync(AddLineItemParam 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", "param"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (string.IsNullOrWhiteSpace(param.ProductId)) { throw new ArgumentException("param.ProductId is required", "param"); } if (param.Quantity <= 0) { throw new ArgumentException("param.Quantity is required", "param"); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException("param.BaseUrl is required", "param"); } var cart = await CartRepository.AddLineItemAsync(param).ConfigureAwait(false); var fixedCart = await FixCartService.FixCartAsync(new FixCartParam { Cart = cart }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = fixedCart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = false, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
/// <summary> /// Add line item to the cart. /// /// CartName will be created if needed /// CustomerId (guest customers) will be created if needed /// If the (product,variant) is already in the cart, the quantity will be increased; /// otherwise a new line will be added /// /// param.VariantId is optional /// /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public async virtual Task <CartViewModel> AddLineItemAsync(AddLineItemParam 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)); } if (string.IsNullOrWhiteSpace(param.ProductId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ProductId)), 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.AddLineItemAsync(param).ConfigureAwait(false); var fixedCart = await FixCartService.FixCartAsync(new FixCartParam { Cart = cart }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = fixedCart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = false, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
public virtual async Task <WishListViewModel> GetWishListViewModelAsync(GetCartParam 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.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } var wishList = await WishListRepository.GetWishListAsync(param).ConfigureAwait(false); var fixedWishlist = await FixCartService.SetFulfillmentLocationIfRequired(new FixCartParam { Cart = wishList }).ConfigureAwait(false); if (wishList == null) { return(null); } return(await CreateWishListViewModelAsync(new CreateWishListViewModelParam() { WishList = fixedWishlist, CultureInfo = param.CultureInfo, BaseUrl = param.BaseUrl })); }
/// <summary> /// Add line item to the cart. /// /// CartName will be created if needed /// CustomerId (guest customers) will be created if needed /// If the (product,variant) is already in the cart, the quantity will be increased; /// otherwise a new line will be added /// /// param.VariantId is optional /// /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public async virtual Task <CartViewModel> AddLineItemAsync(AddLineItemParam 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)); } if (string.IsNullOrWhiteSpace(param.ProductId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ProductId)), 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)); } ProcessedCart cart; try { //If editing order, and line item exists, updating it instead if (param.CartType == CartConfiguration.OrderDraftCartType) { var existingLineItem = await GetExistingLineItem(param).ConfigureAwait(false); if (existingLineItem != null) { var updateLineItemParam = new UpdateLineItemParam { BaseUrl = param.BaseUrl, CartName = param.CartName, CartType = param.CartType, ScopeId = param.Scope, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, LineItemId = existingLineItem.Id, Quantity = param.Quantity + existingLineItem.Quantity, RecurringOrderFrequencyName = param.RecurringOrderFrequencyName, RecurringOrderProgramName = param.RecurringOrderProgramName }; return(await UpdateLineItemAsync(updateLineItemParam).ConfigureAwait(false)); } } cart = await CartRepository.AddLineItemAsync(param).ConfigureAwait(false); } catch (ComposerException ex) { ClearEditModeIfCartDraftDoesNotExist(param.CartType, ex); throw; } if (cart.CartType != CartConfiguration.OrderDraftCartType) { cart = await FixCartService.FixCartAsync(new FixCartParam { Cart = cart, ScopeId = param.Scope }).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); }