public virtual async Task <IHttpActionResult> UpdateCart(UpdateCartRequest updateCartRequest) { if (updateCartRequest == null) { return(BadRequest("updateCartRequest is required")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var getCartParam = new GetCartParam { Scope = ComposerContext.Scope, CultureInfo = ComposerContext.CultureInfo, CustomerId = ComposerContext.CustomerId, CartName = CartConfiguration.ShoppingCartName, BaseUrl = RequestUtils.GetBaseUrl(Request).ToString(), }; var updateCheckoutCartParam = new UpdateCheckoutCartParam { GetCartParam = getCartParam, CurrentStep = updateCartRequest.CurrentStep.GetValueOrDefault(), IsGuest = ComposerContext.IsGuest, UpdateValues = updateCartRequest.UpdatedCart }; var updateCartResultViewModel = await CheckoutService.UpdateCheckoutCartAsync(updateCheckoutCartParam); return(Ok(updateCartResultViewModel)); }
public virtual async Task <IHttpActionResult> UpdateCart(UpdateCartRequest updateCartRequest) { if (updateCartRequest == null) { return(BadRequest("updateCartRequest is required")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var getCartUrlParam = new BaseUrlParameter { CultureInfo = ComposerContext.CultureInfo }; var checkoutStepInfos = CartUrlProvider.GetCheckoutStepPageInfos(getCartUrlParam); var nextStepUrl = CartUrlProvider.GetCheckoutStepUrl(new GetCheckoutStepUrlParam { CultureInfo = ComposerContext.CultureInfo, StepNumber = updateCartRequest.CurrentStep.GetValueOrDefault() + 1 }); var getCartParam = new GetCartParam { Scope = ComposerContext.Scope, CultureInfo = ComposerContext.CultureInfo, CustomerId = ComposerContext.CustomerId, CartName = CartConfiguration.ShoppingCartName, BaseUrl = RequestUtils.GetBaseUrl(Request).ToString(), }; var updateCheckoutCartParam = new UpdateCheckoutCartParam { GetCartParam = getCartParam, CurrentStep = updateCartRequest.CurrentStep.GetValueOrDefault(), IsGuest = ComposerContext.IsGuest, UpdateValues = updateCartRequest.UpdatedCart }; var homepageUrl = GetHomepageUrl(); var updateCartResultViewModel = await CheckoutService.UpdateCheckoutCartAsync(updateCheckoutCartParam); SetHomepageUrl(updateCartResultViewModel.Cart, homepageUrl); SetEditCartUrl(updateCartResultViewModel.Cart); if (updateCartResultViewModel.Cart.OrderSummary != null) { updateCartResultViewModel.Cart.OrderSummary.CheckoutStepUrls = checkoutStepInfos.Values.Select(x => x.Url).ToList(); } if (!updateCartResultViewModel.HasErrors) { updateCartResultViewModel.NextStepUrl = nextStepUrl; } return(Ok(updateCartResultViewModel)); }
/// <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); }
private async Task <LineItem> GetExistingLineItem(AddLineItemParam param) { var getCartParam = new GetCartParam { CartName = param.CartName, Scope = param.Scope, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, CartType = param.CartType, BaseUrl = param.BaseUrl }; var cart = await CartRepository.GetCartAsync(getCartParam).ConfigureAwait(false); return(cart?.GetLineItems()?.Find(x => x.ProductId == param.ProductId && x.VariantId == param.VariantId && !x.IsGiftItem)); }
public virtual async Task <List <ProcessedCart> > GetRecurringCartsAsync(GetRecurringOrderCartsViewModelParam param) { if (param == null) { throw new ArgumentNullException(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 (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } var request = new GetCartsByCustomerIdRequest() { CustomerId = param.CustomerId, ScopeId = param.Scope, CultureName = param.CultureInfo.Name, CartType = CartConfiguration.RecurringOrderCartType }; var cartSummaries = await OvertureClient.SendAsync(request).ConfigureAwait(false); var resultTasks = cartSummaries.Select(cart => { var getCartParam = new GetCartParam { Scope = param.Scope, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, CartName = cart.Name, BaseUrl = param.BaseUrl, ExecuteWorkflow = true }; return(GetCartAsync(getCartParam)); }); var carts = await Task.WhenAll(resultTasks); return(carts.Where(i => i != null).ToList()); }
/// <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("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 cart = await CartRepository.GetCartAsync(param).ConfigureAwait(false); await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, 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); }
public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { var param = new GetCartParam { Scope = scope, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), ExecuteWorkflow = GetRandom.Boolean(), WorkflowToExecute = GetRandom.String(32) }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => _repository.GetCartAsync(param)); //Assert exception.ParamName.Should().BeSameAs("param"); exception.Message.Should().Contain("param.Scope"); }
public void WHEN_CultureInfo_Is_Null_SHOULD_Throw_ArgumentException() { var param = new GetCartParam { Scope = GetRandom.String(32), CultureInfo = null, CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), ExecuteWorkflow = GetRandom.Boolean(), WorkflowToExecute = GetRandom.String(32) }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => _repository.GetCartAsync(param)); //Assert exception.ParamName.Should().BeSameAs("param"); exception.Message.Should().Contain("param.CultureInfo"); }
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 })); }
public void WHEN_Param_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope, string cultureName, string cartName, string customerId, string paramName) { // Arrange var service = _container.CreateInstance <WishListViewService>(); var param = new GetCartParam { Scope = scope, CultureInfo = string.IsNullOrWhiteSpace(cultureName) ? null : CultureInfo.GetCultureInfo(cultureName), CustomerId = string.IsNullOrWhiteSpace(customerId) ? Guid.Empty : GetRandom.Guid(), CartName = cartName }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => service.GetWishListViewModelAsync(param)); //Assert exception.ParamName.Should().BeSameAs("param"); exception.Message.Should().Contain(paramName); }
public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { var param = new GetCartParam { Scope = scope, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), ExecuteWorkflow = GetRandom.Boolean(), WorkflowToExecute = GetRandom.String(32) }; // Act Expression <Func <Task <ProcessedCart> > > expression = () => _repository.GetCartAsync(param); var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke()); //Assert exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name); exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.Scope))); }
public void WHEN_CartName_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string cartName) { // Arrange var service = _container.CreateInstance <WishListViewService>(); var param = new GetCartParam { Scope = "Canada", CultureInfo = CultureInfo.GetCultureInfo("en-CA"), CustomerId = Guid.NewGuid(), CartName = cartName }; // Act Expression <Func <Task <WishListViewModel> > > expression = () => service.GetWishListViewModelAsync(param); var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke()); //Assert exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name); exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.CartName))); }
public void WHEN_CartName_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string cartName) { var service = _container.CreateInstance <CartService>(); var param = new GetCartParam { Scope = GetRandom.String(32), CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = cartName, ExecuteWorkflow = GetRandom.Boolean(), WorkflowToExecute = GetRandom.String(32), BaseUrl = GetRandom.String(32) }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => service.GetCartViewModelAsync(param)); //Assert exception.ParamName.Should().BeSameAs("param"); exception.Message.Should().Contain("param.CartName"); }
public void WHEN_CustomerId_Is_Empty_SHOULD_Throw_ArgumentException() { // Arrange _container.Use(OvertureClientFactory.Create()); var repository = _container.CreateInstance <WishListRepository>(); var param = new GetCartParam { Scope = "Canada", CultureInfo = CultureInfo.GetCultureInfo("en-CA"), CustomerId = Guid.Empty, CartName = "WishList" }; // Act Expression <Func <Task <ProcessedCart> > > expression = () => repository.GetWishListAsync(param); var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke()); //Assert exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name); exception.Message.Should().StartWith(GetMessageOfEmpty(nameof(param.CustomerId))); }
public void WHEN_CartName_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string cartName) { var service = _container.CreateInstance <CartService>(); var param = new GetCartParam { Scope = GetRandom.String(32), CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = cartName, ExecuteWorkflow = GetRandom.Boolean(), WorkflowToExecute = GetRandom.String(32), BaseUrl = GetRandom.String(32) }; // Act Expression <Func <Task <CartViewModel> > > expression = () => service.GetCartViewModelAsync(param); var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke()); //Assert exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name); exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.CartName))); }
/// <summary> /// Retrieve a cart. /// The cart is created if it does not exist. /// </summary> /// <param name="param"></param> /// <returns>The Processed Cart requested or an empty one if it doesn't exist</returns> public virtual Task <ProcessedCart> GetCartAsync(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)); } var cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); var request = new GetCartRequest { CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope, CartName = param.CartName, CartType = param.CartType, //Reexecute price engine and promotion engine is automatically done at each request ExecuteWorkflow = param.ExecuteWorkflow, WorkflowToExecute = param.WorkflowToExecute }; return(CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
public virtual async Task <ProcessedCart> GetWishListAsync(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 cacheKey = BuildWishListCacheKey(param.Scope, param.CustomerId, param.CartName); var request = new GetCartRequest { CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope, CartName = param.CartName, ExecuteWorkflow = param.ExecuteWorkflow, WorkflowToExecute = param.WorkflowToExecute }; return(await CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(request)).ConfigureAwait(false)); }
public Task <ProcessedCart> GetCartAsync(GetCartParam param) { return(Task.FromResult(CurrentCart)); }
public virtual async Task <WishListSummaryViewModel> GetWishListSummaryViewModelAsync(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); if (wishList == null) { return(null); } return(CreateSummaryWishListViewModel(new CreateWishListViewModelParam { WishList = wishList, CultureInfo = param.CultureInfo, BaseUrl = param.BaseUrl, WebsiteId = param.WebsiteId })); }