public async Task<ActionResult> GetActualProductPricesJson(Product[] products) { var prices = new List<ProductPrice>(); if (products == null) { return Json(prices, JsonRequestBehavior.AllowGet); } var pricesResponse = await _pricingApi.PricingModuleEvaluatePricesAsync( evalContextProductIds: products.Select(p => p.Id).ToList(), evalContextCatalogId: WorkContext.CurrentStore.Catalog, evalContextCurrency: WorkContext.CurrentCurrency.Code, evalContextCustomerId: WorkContext.CurrentCustomer.Id, evalContextLanguage: WorkContext.CurrentLanguage.CultureName, evalContextStoreId: WorkContext.CurrentStore.Id); if (pricesResponse == null) { return Json(prices, JsonRequestBehavior.AllowGet); } prices = pricesResponse.Select(p => p.ToWebModel()).ToList(); var promotionContext = new PromotionEvaluationContext { CartPromoEntries = GetCartPromoEntries(WorkContext.CurrentCart), Currency = WorkContext.CurrentCurrency, CustomerId = WorkContext.CurrentCustomer.Id, IsRegisteredUser = WorkContext.CurrentCustomer.HasAccount, Language = WorkContext.CurrentLanguage, PromoEntries = GetPromoEntries(products, prices), StoreId = WorkContext.CurrentStore.Id }; foreach (var product in products) { product.Currency = WorkContext.CurrentCurrency; product.Price = prices.FirstOrDefault(p => p.ProductId == product.Id); } await _promotionEvaluator.EvaluateDiscountsAsync(promotionContext, products); prices = products.Select(p => p.Price).ToList(); foreach (var price in prices) { if (price.ActiveDiscount != null) { price.AbsoluteBenefit += price.ActiveDiscount.Amount; price.ActualPrice = price.SalePrice - price.AbsoluteBenefit; } } return Json(prices, JsonRequestBehavior.AllowGet); }
public async Task<ActionResult> GetActualProductPricesJson(Product[] products) { if(products == null) { throw new ArgumentNullException("products"); } //Evaluate products prices await _pricingService.EvaluateProductPricesAsync(products); //Evaluate discounts var promotionContext = WorkContext.ToPromotionEvaluationContext(); promotionContext.PromoEntries = products.Select(x => x.ToPromotionItem()).ToList(); await _promotionEvaluator.EvaluateDiscountsAsync(promotionContext, products); var retVal = products.Select(x => x.Price).ToArray(); return Json(retVal, JsonRequestBehavior.AllowGet); }
public async Task<ActionResult> GetActualProductPricesJson(Product[] products) { var prices = new List<ProductPrice>(); if (products == null) { return Json(prices, JsonRequestBehavior.AllowGet); } var pricesResponse = await _pricingApi.PricingModuleEvaluatePricesAsync( evalContextProductIds: products.Select(p => p.Id).ToList(), evalContextCatalogId: WorkContext.CurrentStore.Catalog, evalContextCurrency: WorkContext.CurrentCurrency.Code, evalContextCustomerId: WorkContext.CurrentCustomer.Id, evalContextLanguage: WorkContext.CurrentLanguage.CultureName, evalContextStoreId: WorkContext.CurrentStore.Id); if (pricesResponse == null) { return Json(prices, JsonRequestBehavior.AllowGet); } prices = pricesResponse.Select(p => p.ToWebModel()).ToList(); var promotionContext = WorkContext.ToPromotionEvaluationContext(); promotionContext.PromoEntries = GetPromoEntries(products, prices); foreach (var product in products) { product.Currency = WorkContext.CurrentCurrency; product.Price = prices.FirstOrDefault(p => p.ProductId == product.Id); } await _promotionEvaluator.EvaluateDiscountsAsync(promotionContext, products); return Json(prices, JsonRequestBehavior.AllowGet); }
private void LoadProductsInventories(Product[] products) { var inventories = _inventoryModuleApi.InventoryModuleGetProductsInventories(products.Select(x => x.Id).ToList()); foreach (var item in products) { item.Inventory = inventories.Where(x => x.ProductId == item.Id).Select(x => x.ToWebModel()).FirstOrDefault(); } }
private void LoadProductsPrices(Product[] products) { var result = _pricingModuleApi.PricingModuleEvaluatePrices( evalContextStoreId: _workContext.CurrentStore.Id, evalContextCatalogId: _workContext.CurrentStore.Catalog, evalContextProductIds: products.Select(x => x.Id).ToList(), evalContextCustomerId: _workContext.CurrentCustomer.Id, evalContextCertainDate: _workContext.StorefrontUtcNow, evalContextPricelistIds: _workContext.CurrentPriceListIds.ToList()); foreach (var item in products) { item.Prices = result.Where(x => x.ProductId == item.Id).Select(x => x.ToWebModel()).ToList(); var price = item.Prices.FirstOrDefault(x => x.Currency.Equals(_workContext.CurrentCurrency)); if (price != null) { item.Price = price; } } }
private async Task LoadProductsDiscountsAsync(Product[] products) { var promotionContext = _workContext.ToPromotionEvaluationContext(); promotionContext.PromoEntries = products.Select(x=>x.ToPromotionItem()).ToList(); await _promotionEvaluator.EvaluateDiscountsAsync(promotionContext, products); }