Beispiel #1
0
        /// <summary>
        /// Get a value indicating whether a customer is consumer (a person, not a company) located in Europe Union
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <returns>Result</returns>
        protected virtual async Task <bool> IsEuConsumer(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            Country country = null;

            //get country from billing address
            if (_addressSettings.CountryEnabled && customer.BillingAddress != null)
            {
                var _country = await _countryService.GetCountryById(customer.BillingAddress.CountryId);

                country = _country;
            }
            //get country specified during registration?
            if (country == null && _customerSettings.CountryEnabled)
            {
                var countryId = customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.CountryId);
                country = await _countryService.GetCountryById(countryId);
            }

            //get country by IP address
            if (country == null && _taxSettings.GetCountryByIPAddress)
            {
                var ipAddress      = customer.LastIpAddress;
                var countryIsoCode = _geoLookupService.LookupCountryIsoCode(ipAddress);
                country = await _countryService.GetCountryByTwoLetterIsoCode(countryIsoCode);
            }

            //we cannot detect country
            if (country == null)
            {
                return(false);
            }

            //outside EU
            if (!country.SubjectToVat)
            {
                return(false);
            }

            //company (business) or consumer?
            var customerVatStatus = (VatNumberStatus)customer.GetAttributeFromEntity <int>(SystemCustomerAttributeNames.VatNumberStatusId);

            if (customerVatStatus == VatNumberStatus.Valid)
            {
                return(false);
            }

            //TODO: use specified company name? (both address and registration one)

            //consumer
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Get a value indicating whether a customer is consumer (a person, not a company) located in Europe Union
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <returns>Result</returns>
        protected virtual bool IsEuConsumer(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            Country country = null;

            //get country from billing address
            if (_addressSettings.CountryEnabled && customer.BillingAddress != null)
            {
                country = customer.BillingAddress.Country;
            }

            //get country specified during registration?
            if (country == null && _customerSettings.CountryEnabled)
            {
                var countryId = _genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.CountryIdAttribute);
                country = _countryService.GetCountryById(countryId);
            }

            //get country by IP address
            if (country == null)
            {
                var ipAddress      = _webHelper.GetCurrentIpAddress();
                var countryIsoCode = _geoLookupService.LookupCountryIsoCode(ipAddress);
                country = _countryService.GetCountryByTwoLetterIsoCode(countryIsoCode);
            }

            //we cannot detect country
            if (country == null)
            {
                return(false);
            }

            //outside EU
            if (!country.SubjectToVat)
            {
                return(false);
            }

            //company (business) or consumer?
            var customerVatStatus = (VatNumberStatus)_genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.VatNumberStatusIdAttribute);

            if (customerVatStatus == VatNumberStatus.Valid)
            {
                return(false);
            }

            //TODO: use specified company name? (both address and registration one)

            //consumer
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Get a value indicating whether a customer is consumer (a person, not a company) located in Europe Union
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the result
        /// </returns>
        protected virtual async Task <bool> IsEuConsumerAsync(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            Country country = null;

            //get country from billing address
            if (_addressSettings.CountryEnabled && await _customerService.GetCustomerShippingAddressAsync(customer) is Address billingAddress)
            {
                country = await _countryService.GetCountryByAddressAsync(billingAddress);
            }

            //get country specified during registration?
            if (country == null && _customerSettings.CountryEnabled)
            {
                var countryId = await _genericAttributeService.GetAttributeAsync <Customer, int>(customer.Id, NopCustomerDefaults.CountryIdAttribute);

                country = await _countryService.GetCountryByIdAsync(countryId);
            }

            //get country by IP address
            if (country == null)
            {
                var ipAddress      = _webHelper.GetCurrentIpAddress();
                var countryIsoCode = _geoLookupService.LookupCountryIsoCode(ipAddress);
                country = await _countryService.GetCountryByTwoLetterIsoCodeAsync(countryIsoCode);
            }

            //we cannot detect country
            if (country == null)
            {
                return(false);
            }

            //outside EU
            if (!country.SubjectToVat)
            {
                return(false);
            }

            //company (business) or consumer?
            var customerVatStatus = (VatNumberStatus)await _genericAttributeService.GetAttributeAsync <int>(customer, NopCustomerDefaults.VatNumberStatusIdAttribute);

            if (customerVatStatus == VatNumberStatus.Valid)
            {
                return(false);
            }

            //consumer
            return(true);
        }
 /// <summary>
 /// Get country name
 /// </summary>
 /// <param name="ipAddress">IP address</param>
 /// <returns>Country name</returns>
 public string LookupCountryIsoCode(string ipAddress)
 {
     return(_geoLookupService.LookupCountryIsoCode(ipAddress));
 }