Пример #1
0
        public virtual async Task <ICollection <ShippingMethod> > GetAvailableShippingMethodsAsync()
        {
            var availableShippingMethods = new List <ShippingMethod>();

            // TODO: Remake with shipmentId
            var serviceModels = await _cartApi.CartModuleGetShipmentMethodsAsync(_cart.Id);

            foreach (var serviceModel in serviceModels)
            {
                availableShippingMethods.Add(serviceModel.ToWebModel(_cart.Currency));
            }
            //Evaluate tax for shipping methods
            var taxEvalContext = _cart.ToTaxEvalContext();

            taxEvalContext.Lines.Clear();
            taxEvalContext.Lines.AddRange(availableShippingMethods.Select(x => x.ToTaxLine()));
            var taxResult = await _commerceApi.CommerceEvaluateTaxesAsync(_cart.StoreId, taxEvalContext);

            if (taxResult != null)
            {
                var taxRates = taxResult.Select(x => x.ToWebModel(_cart.Currency)).ToList();
                foreach (var shippingMethod in availableShippingMethods)
                {
                    shippingMethod.ApplyTaxRates(taxRates);
                }
            }
            //Evaluate promotions for shipping methods
            var promoEvalContext = _cart.ToPromotionEvaluationContext();
            await _promotionEvaluator.EvaluateDiscountsAsync(promoEvalContext, availableShippingMethods);

            return(availableShippingMethods);
        }
Пример #2
0
        public async Task EvaluateProductPricesAsync(ICollection <Product> products)
        {
            var workContext = _workContextFactory();
            //Evaluate products prices
            var evalContext = products.ToServiceModel(workContext);

            var pricesResponse = await _pricingApi.PricingModuleEvaluatePricesAsync(evalContext);

            ApplyProductPricesInternal(products, pricesResponse);
            //Evaluate product taxes
            var taxEvalContext = workContext.ToTaxEvaluationContext(products);
            var taxRates       = await _commerceApi.CommerceEvaluateTaxesAsync(workContext.CurrentStore.Id, taxEvalContext);

            ApplyProductTaxInternal(products, taxRates);
        }