Beispiel #1
0
        public ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            var customers = _customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(-_customerSettings.OnlineCustomerMinutes),
                                                                null, 0, _adminAreaSettings.GridPageSize);

            var model = new GridModel <OnlineCustomerModel>
            {
                Data = customers.Select(x =>
                {
                    return(new OnlineCustomerModel
                    {
                        Id = x.Id,
                        CustomerInfo = x.IsRegistered() ? x.Email : T("Admin.Customers.Guest").Text,
                        LastIpAddress = x.LastIpAddress,
                        Location = _geoCountryLookup.LookupCountry(x.LastIpAddress)?.Name.EmptyNull(),
                        LastActivityDate = _dateTimeHelper.ConvertToUserTime(x.LastActivityDateUtc, DateTimeKind.Utc),
                        LastVisitedPage = x.GetAttribute <string>(SystemCustomerAttributeNames.LastVisitedPage)
                    });
                }),
                Total = customers.TotalCount
            };

            return(View(model));
        }
Beispiel #2
0
        /// <summary>
        /// Gets a value indicating whether the given customer is a consumer (NOT a business/company) within the EU
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <returns><c>true</c> if the customer is a consumer, <c>false</c> otherwise</returns>
        /// <remarks>
        /// A customer is assumed to be a consumer if the default tax address doesn't include a company name,
        /// OR if a company name was specified but the EU VAT number for this record is invalid.
        /// </remarks>
        protected virtual bool IsEuConsumer(Customer customer)
        {
            if (customer == null)
            {
                return(false);
            }

            var address = customer.BillingAddress;

            if (address != null && address.Company.IsEmpty())
            {
                // BillingAddress is explicitly set, but no CompanyName in there: so we assume a consumer
                return(true);
            }

            // No Country or BillingAddress set: try to resolve country from IP address
            var subjectToVat = _geoCountryLookup.LookupCountry(customer.LastIpAddress)?.IsInEu == true;

            if (!subjectToVat)
            {
                return(false);
            }

            // It's EU: check VAT number status
            var vatStatus = (VatNumberStatus)customer.GetAttribute <int>(SystemCustomerAttributeNames.VatNumberStatusId);

            // companies with invalid VAT numbers are assumed to be consumers
            return(vatStatus != VatNumberStatus.Valid);
        }
Beispiel #3
0
        public Task <bool> MatchAsync(CartRuleContext context, RuleExpression expression)
        {
            var country = _countryLookup.LookupCountry(_webHelper.GetClientIpAddress());
            var match   = expression.HasListMatch(country?.IsoCode ?? string.Empty, StringComparer.InvariantCultureIgnoreCase);

            return(Task.FromResult(match));
        }
Beispiel #4
0
        public void CanLookup()
        {
            foreach (var kvp in _addresses)
            {
                var ip     = kvp.Key;
                var expect = kvp.Value;

                var response = _geoCountryLookup.LookupCountry(ip);

                Assert.AreEqual(expect.IsoCode, response.IsoCode, response.Name);
                Assert.AreEqual(expect.Name, response.Name, response.Name);
                Assert.AreEqual(expect.IsInEu, response.IsInEu, response.Name);
            }
        }
        private bool DisplayForCountry()
        {
            var ipAddress             = _webHelper.GetCurrentIpAddress();
            var lookUpCountryResponse = _geoCountryLookup.LookupCountry(ipAddress);

            if (lookUpCountryResponse == null || lookUpCountryResponse.IsoCode == null)
            {
                // No country was found (e.g. localhost), so we better return true.
                return(true);
            }

            var country = _countryService.GetCountryByTwoLetterIsoCode(lookUpCountryResponse.IsoCode);

            if (country != null && country.DisplayCookieManager)
            {
                // Country was configured to display cookie manager.
                return(true);
            }

            return(false);
        }
Beispiel #6
0
        private async Task <bool> DisplayForCountryAsync()
        {
            var ipAddress             = _webHelper.GetClientIpAddress();
            var lookUpCountryResponse = _countryLookup.LookupCountry(ipAddress);

            if (lookUpCountryResponse?.IsoCode == null)
            {
                // No country was found (e.g. localhost), so we better return true.
                return(true);
            }

            var country = await _db.Countries
                          .AsNoTracking()
                          .ApplyIsoCodeFilter(lookUpCountryResponse.IsoCode)
                          .FirstOrDefaultAsync();

            if (country != null && country.DisplayCookieManager)
            {
                // Country was configured to display cookie manager.
                return(true);
            }

            return(false);
        }
Beispiel #7
0
        protected override string GetValue(CartRuleContext context)
        {
            var country = _countryLookup.LookupCountry(_webHelper.GetCurrentIpAddress());

            return(country?.IsoCode ?? string.Empty);
        }