Ejemplo n.º 1
0
        /// <summary>
        /// Gets tax rate
        /// </summary>
        /// <param name="product">Product</param>
        /// <param name="taxCategoryId">Tax category identifier</param>
        /// <param name="customer">Customer</param>
        /// <param name="price">Price (taxable value)</param>
        /// <param name="taxRate">Calculated tax rate</param>
        /// <param name="isTaxable">A value indicating whether a request is taxable</param>
        protected virtual void GetTaxRate(Product product, int taxCategoryId,
                                          Customer customer, decimal price, out decimal taxRate, out bool isTaxable)
        {
            taxRate   = decimal.Zero;
            isTaxable = true;

            //active tax provider
            var activeTaxProvider = _taxPluginManager.LoadPrimaryPlugin(customer, _storeContext.CurrentStore.Id);

            if (activeTaxProvider == null)
            {
                return;
            }

            //tax request
            var taxRateRequest = PrepareTaxRateRequest(product, taxCategoryId, customer, price);

            //tax exempt
            if (IsTaxExempt(product, taxRateRequest.Customer))
            {
                isTaxable = false;
            }

            //make EU VAT exempt validation (the European Union Value Added Tax)
            if (isTaxable &&
                _taxSettings.EuVatEnabled &&
                IsVatExempt(taxRateRequest.Address, taxRateRequest.Customer))
            {
                //VAT is not chargeable
                isTaxable = false;
            }

            //get tax rate
            var taxRateResult = activeTaxProvider.GetTaxRate(taxRateRequest);

            //tax rate is calculated, now consumers can adjust it
            _eventPublisher.Publish(new TaxRateCalculatedEvent(taxRateResult));

            if (taxRateResult.Success)
            {
                //ensure that tax is equal or greater than zero
                if (taxRateResult.TaxRate < decimal.Zero)
                {
                    taxRateResult.TaxRate = decimal.Zero;
                }

                taxRate = taxRateResult.TaxRate;
            }
            else if (_taxSettings.LogErrors)
            {
                foreach (var error in taxRateResult.Errors)
                {
                    _logger.Error($"{activeTaxProvider.PluginDescriptor.FriendlyName} - {error}", null, customer);
                }
            }
        }
Ejemplo n.º 2
0
        public void Can_load_active_taxProvider()
        {
            var serviceProvider = new FakeServiceProvider(_genericAttributeService.Object, _taxService, _taxSettings);
            var nopEngine       = new FakeNopEngine(serviceProvider);

            EngineContext.Replace(nopEngine);

            var provider = _taxPluginManager.LoadPrimaryPlugin();

            provider.Should().NotBeNull();

            EngineContext.Replace(null);
        }
Ejemplo n.º 3
0
        public void Can_load_active_taxProvider()
        {
            var provider = _taxPluginManager.LoadPrimaryPlugin();

            provider.ShouldNotBeNull();
        }
Ejemplo n.º 4
0
        public void CanLoadActiveTaxProvider()
        {
            var provider = _taxPluginManager.LoadPrimaryPlugin();

            provider.Should().NotBeNull();
        }