public void CheckoutQuoteRequest() { WorkContext workContext = GetTestWorkContext(); IQuoteRequestBuilder quoteRequestBuilder = GetQuoteRequestBuilder(); var customer = new CustomerInfo { Id = Guid.NewGuid().ToString(), IsRegisteredUser = false }; workContext.CurrentCustomer = customer; QuoteRequest quoteRequest = quoteRequestBuilder.GetOrCreateNewTransientQuoteRequestAsync(workContext.CurrentStore, customer, workContext.CurrentLanguage, workContext.CurrentCurrency).Result.QuoteRequest; ICatalogSearchService catalogSearchService = GetCatalogSearchService(); Product[] searchResult = catalogSearchService.GetProductsAsync(new[] { "217be9f3d9064075821f6785dca658b9" }, ItemResponseGroup.ItemLarge).Result; quoteRequestBuilder.AddItem(searchResult.First(), 1); quoteRequestBuilder.SaveAsync().Wait(); var quoteItem = quoteRequestBuilder.QuoteRequest.Items.First(); quoteItem.ProposalPrices.Add(new TierPrice(quoteItem.SalePrice * 0.7, 5)); quoteItem.ProposalPrices.Add(new TierPrice(quoteItem.SalePrice * 0.5, 10)); quoteRequestBuilder.SaveAsync().Wait(); quoteRequest = quoteRequestBuilder.GetOrCreateNewTransientQuoteRequestAsync(workContext.CurrentStore, customer, workContext.CurrentLanguage, workContext.CurrentCurrency).Result.QuoteRequest; Assert.NotNull(quoteRequest.Items); Assert.Equal(quoteRequest.Items.Count, 1); var requestItem = quoteRequest.Items.First(); foreach (var proposalPrice in requestItem.ProposalPrices) { requestItem.SelectedTierPrice = proposalPrice; ICartBuilder cartBuilder = GetCartBuilder(); cartBuilder.LoadOrCreateNewTransientCartAsync("default", workContext.CurrentStore, customer, workContext.CurrentLanguage, workContext.CurrentCurrency).Wait(); cartBuilder.FillFromQuoteRequestAsync(quoteRequest).Wait(); cartBuilder.SaveAsync().Wait(); cartBuilder.LoadOrCreateNewTransientCartAsync("default", workContext.CurrentStore, customer, workContext.CurrentLanguage, workContext.CurrentCurrency).Wait(); var cart = cartBuilder.Cart; var item = cart.Items.First(); Assert.Equal(requestItem.SelectedTierPrice.ActualPrice, item.SalePrice); Assert.Equal(requestItem.SelectedTierPrice.Quantity, item.Quantity); } }
public async Task <ActionResult> AddItemJson(string productId, long quantity) { EnsureThatQuoteRequestExists(); using (var lockObject = await AsyncLock.GetLockByKey("quote-product:" + productId).LockAsync()) { var products = await _catalogSearchService.GetProductsAsync(new string[] { productId }, ItemResponseGroup.ItemLarge); if (products != null && products.Any()) { _quoteRequestBuilder.AddItem(products.First(), quantity); await _quoteRequestBuilder.SaveAsync(); } } return(Json(null, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> AddItem([FromBody] AddQuoteItem addQuoteItem) { EnsureQuoteRequestBelongsToCurrentCustomer(WorkContext.CurrentQuoteRequest.Value); _quoteRequestBuilder.TakeQuoteRequest(WorkContext.CurrentQuoteRequest.Value); using (await AsyncLock.GetLockByKey(GetAsyncLockQuoteKey(_quoteRequestBuilder.QuoteRequest.Id)).LockAsync()) { var products = await _catalogService.GetProductsAsync(new[] { addQuoteItem.ProductId }, ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemWithPrices); if (products != null && products.Any()) { _quoteRequestBuilder.AddItem(products.First(), addQuoteItem.Quantity); await _quoteRequestBuilder.SaveAsync(); } } return(Ok()); }
public async Task <ActionResult> AddItem(string productId, int quantity) { EnsureQuoteRequestBelongsToCurrentCustomer(WorkContext.CurrentQuoteRequest); _quoteRequestBuilder.TakeQuoteRequest(WorkContext.CurrentQuoteRequest); using (await AsyncLock.GetLockByKey(GetAsyncLockQuoteKey(_quoteRequestBuilder.QuoteRequest.Id)).LockAsync()) { var products = await _catalogSearchService.GetProductsAsync(new[] { productId }, ItemResponseGroup.ItemLarge); if (products != null && products.Any()) { _quoteRequestBuilder.AddItem(products.First(), quantity); await _quoteRequestBuilder.SaveAsync(); } } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }