Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Remove unused GetCountryByIPAddress property and related code

supporta54e36117764
diff --git a/src/Business/Grand.Business.Catalog/Services/Directory/GeoLookupService.cs b/src/Business/Grand.Business.Catalog/Services/Directory/GeoLookupService.cs
deleted file mode 100644
index e7e788452..000000000
--- a/src/Business/Grand.Business.Catalog/Services/Directory/GeoLookupService.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-//This product contains GeoLite2 data created by MaxMind, from http://www.maxmind.com
-
-using Grand.Business.Core.Interfaces.Catalog.Directory;
-using Grand.SharedKernel.Extensions;
-using MaxMind.GeoIP2;
-using MaxMind.GeoIP2.Exceptions;
-using MaxMind.GeoIP2.Responses;
-using Microsoft.Extensions.Logging;
-
-namespace Grand.Business.Catalog.Services.Directory;
-
-/// <summary>
-/// GEO lookup service
-/// </summary>
-public class GeoLookupService : IGeoLookupService
-{
- #region Fields
-
- private readonly ILogger<GeoLookupService> _logger;
-
- #endregion
-
- #region Ctor
-
- public GeoLookupService(ILogger<GeoLookupService> logger)
- {
- _logger = logger;
- }
-
- #endregion
-
- #region Utilities
-
- protected virtual CountryResponse GetInformation(string ipAddress)
- {
- if (string.IsNullOrEmpty(ipAddress))
- return null;
-
- try
- {
- //This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com
- var databasePath = CommonPath.MapPath("App_Data/GeoLite2-Country.mmdb");
- var reader = new DatabaseReader(databasePath);
- var response = reader.Country(ipAddress);
- return response;
- //more info: http://maxmind.github.io/GeoIP2-dotnet/
- //more info: https://github.com/maxmind/GeoIP2-dotnet
- }
- catch (GeoIP2Exception)
- {
- return null;
- }
- catch (Exception exc)
- {
- _logger.LogError(exc, "Cannot load MaxMind record");
- return null;
- }
- }
-
- #endregion
-
- #region Methods
-
- /// <summary>
- /// Get country name
- /// </summary>
- /// <param name="ipAddress">IP address</param>
- /// <returns>Country name</returns>
- public virtual string CountryIsoCode(string ipAddress)
- {
- var response = GetInformation(ipAddress);
- return response is not null ? response.Country.IsoCode : "";
- }
-
- /// <summary>
- /// Get country name
- /// </summary>
- /// <param name="ipAddress">IP address</param>
- /// <returns>Country name</returns>
- public virtual string CountryName(string ipAddress)
- {
- var response = GetInformation(ipAddress);
- return response is not null ? response.Country.Name : "";
- }
-
- #endregion
-}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Catalog/Services/Tax/TaxService.cs b/src/Business/Grand.Business.Catalog/Services/Tax/TaxService.cs
index abeddc1a3..92c6690dc 100644
--- a/src/Business/Grand.Business.Catalog/Services/Tax/TaxService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Tax/TaxService.cs
@@ -24,7 +24,6 @@ public class TaxService : ITaxService
public TaxService(
IWorkContext workContext,
IGroupService groupService,
- IGeoLookupService geoLookupService,
ICountryService countryService,
IEnumerable<ITaxProvider> taxProviders,
ILogger<TaxService> logger,
@@ -38,7 +37,6 @@ public class TaxService : ITaxService
_taxSettings = taxSettings;
_taxProviderSettings = taxProviderSettings;
_taxProviders = taxProviders;
- _geoLookupService = geoLookupService;
_logger = logger;
_countryService = countryService;
_customerSettings = customerSettings;
@@ -51,7 +49,6 @@ public class TaxService : ITaxService
private readonly IWorkContext _workContext;
private readonly IGroupService _groupService;
- private readonly IGeoLookupService _geoLookupService;
private readonly ICountryService _countryService;
private readonly IEnumerable<ITaxProvider> _taxProviders;
private readonly ILogger<TaxService> _logger;
@@ -85,14 +82,6 @@ public class TaxService : ITaxService
country = await _countryService.GetCountryById(countryId);
}
- //get country by IP address
- if (country == null && _taxSettings.GetCountryByIPAddress)
- {
- var ipAddress = customer.LastIpAddress;
- var countryIsoCode = _geoLookupService.CountryIsoCode(ipAddress);
- country = await _countryService.GetCountryByTwoLetterIsoCode(countryIsoCode);
- }
-
//we cannot detect country
if (country is not { SubjectToVat: true })
return false;
diff --git a/src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs b/src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs
index 738b1ae89..26fdaecfd 100644
--- a/src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs
+++ b/src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs
@@ -72,7 +72,6 @@ public class StartupApplication : IStartupApplication
serviceCollection.AddScoped<IStockQuantityService, StockQuantityService>();
serviceCollection.AddScoped<IPricingService, PricingService>();
serviceCollection.AddScoped<ISearchTermService, SearchTermService>();
- serviceCollection.AddScoped<IGeoLookupService, GeoLookupService>();
serviceCollection.AddScoped<IMeasureService, MeasureService>();
}
diff --git a/src/Business/Grand.Business.Core/Interfaces/Catalog/Directory/IGeoLookupService.cs b/src/Business/Grand.Business.Core/Interfaces/Catalog/Directory/IGeoLookupService.cs
deleted file mode 100644
index ec331b925..000000000
--- a/src/Business/Grand.Business.Core/Interfaces/Catalog/Directory/IGeoLookupService.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace Grand.Business.Core.Interfaces.Catalog.Directory;
-
-/// <summary>
-/// GEO lookup service
-/// </summary>
-public interface IGeoLookupService
-{
- /// <summary>
- /// Get country name
- /// </summary>
- /// <param name="ipAddress">IP address</param>
- /// <returns>Country name</returns>
- string CountryIsoCode(string ipAddress);
-
- /// <summary>
- /// Get country name
- /// </summary>
- /// <param name="ipAddress">IP address</param>
- /// <returns>Country name</returns>
- string CountryName(string ipAddress);
-}
\ No newline at end of file
diff --git a/src/Core/Grand.Domain/Tax/TaxSettings.cs b/src/Core/Grand.Domain/Tax/TaxSettings.cs
index f7abf8155..4fccbe4e8 100644
--- a/src/Core/Grand.Domain/Tax/TaxSettings.cs
+++ b/src/Core/Grand.Domain/Tax/TaxSettings.cs
@@ -112,11 +112,6 @@ public class TaxSettings : ISettings
/// </summary>
public bool EuVatAssumeValid { get; set; }
- /// <summary>
- /// Gets or sets a value indicating whether we should read country by address IP
- /// </summary>
- public bool GetCountryByIPAddress { get; set; }
-
/// <summary>
/// Gets or sets a value indicating for rounding calulate price
/// </summary>
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Directory/GeoLookupServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Directory/GeoLookupServiceTests.cs
deleted file mode 100644
index 797f1dfca..000000000
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Directory/GeoLookupServiceTests.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using Grand.Business.Catalog.Services.Directory;
-using Grand.SharedKernel.Extensions;
-using Microsoft.Extensions.Logging;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-
-namespace Grand.Business.Catalog.Tests.Services.Directory;
-
-[TestClass]
-public class GeoLookupServiceTests
-{
- private readonly string IPAddressUS = "142.250.203.206";
- private Mock<ILogger<GeoLookupService>> _loggerMock;
- private GeoLookupService _service;
-
- [TestInitialize]
- public void Init()
- {
- CommonPath.BaseDirectory = "../../../../../Web/Grand.Web/";
- _loggerMock = new Mock<ILogger<GeoLookupService>>();
- _service = new GeoLookupService(_loggerMock.Object);
- }
-
-
- [TestMethod]
- public void CountryIsoCodeTest()
- {
- var countryiso = _service.CountryIsoCode(IPAddressUS);
- Assert.AreEqual("US", countryiso);
- }
-
- [TestMethod]
- public void CountryNameTest()
- {
- var countryname = _service.CountryName(IPAddressUS);
- Assert.AreEqual("United States", countryname);
- }
-}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs
index 7b718585a..ae74b2fbf 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs
@@ -20,7 +20,6 @@ public class TaxServiceTests
private AddressSettings _addressSettings;
private ICountryService _countryService;
private CustomerSettings _customerSettings;
- private IGeoLookupService _geoLookupService;
private Mock<IGroupService> _groupServiceMock;
private Mock<ILogger<TaxService>> _loggerMock;
@@ -48,7 +47,6 @@ public class TaxServiceTests
_taxSettings = new TaxSettings();
_workContext = null;
- _geoLookupService = new Mock<IGeoLookupService>().Object;
_countryService = new Mock<ICountryService>().Object;
_customerSettings = new CustomerSettings();
_addressSettings = new AddressSettings();
@@ -57,7 +55,7 @@ public class TaxServiceTests
var providers = new List<ITaxProvider>();
providers.Add(new FixedRateTestTaxProvider());
_taxService = new TaxService(_workContext, _groupServiceMock.Object,
- _geoLookupService, _countryService, providers, _loggerMock.Object,
+ _countryService, providers, _loggerMock.Object,
_taxSettings, _taxProviderSettings, _customerSettings, _addressSettings);
_vatService = new VatService(_taxSettings);
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/OnlineCustomer/List.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/OnlineCustomer/List.cshtml
index 249024d78..7c33523f1 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/OnlineCustomer/List.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/OnlineCustomer/List.cshtml
@@ -65,10 +65,6 @@
field: "LastIpAddress",
title: "@Loc["Admin.Dashboards.OnlineCustomers.Fields.IPAddress"]",
width: 100,
- }, {
- field: "Location",
- title: "@Loc["Admin.Dashboards.OnlineCustomers.Fields.Location"]",
- width: 150,
}, {
field: "LastActivityDate",
title: "@Loc["Admin.Dashboards.OnlineCustomers.Fields.LastActivityDate"]",
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Tax/Settings.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Tax/Settings.cshtml
index f40e13b4b..74e2f2220 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Tax/Settings.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Tax/Settings.cshtml
@@ -58,7 +58,6 @@
$('#pnlEuVatAllowVATExemption').show();
$('#pnlEuVatAssumeValid').show();
$('#pnlEuVatUseWebService').show();
- $('#pnlEuVatEmailAdminWhenNewVATSubmitted').show();
$('#pnlEuVatNote').show();
}
else {
@@ -66,7 +65,6 @@
$('#pnlEuVatAllowVATExemption').hide();
$('#pnlEuVatAssumeValid').hide();
$('#pnlEuVatUseWebService').hide();
- $('#pnlEuVatEmailAdminWhenNewVATSubmitted').hide();
$('#pnlEuVatNote').hide();
}
}
@@ -338,18 +336,6 @@
If you want to use EU VAT Web Service to validate the EU VAT numbers, please add EuropaCheckVat plugin to your store. It can be found <a href="https://github.com/grandnode/Grand.Plugin.Misc.EuropaCheckVat" target="_blank">here</a>.
</div>
</div>
-<div class="form-group" id="pnlEuVatEmailAdminWhenNewVATSubmitted">
- <div class="col-8 col-md-4 col-sm-4 text-right">
- <admin-label asp-for="GetCountryByIPAddress" class="control-label"/>
- </div>
- <div class="col-4 col-md-8 col-sm-8">
- <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
- <admin-input asp-for="GetCountryByIPAddress"/>
- <div class="control__indicator"></div>
- </label>
- <span asp-validation-for="GetCountryByIPAddress"></span>
- </div>
-</div>
<div class="form-group">
<div class="col-8 col-md-4 col-sm-4 text-right">
<admin-label asp-for="CalculateRoundPrice" class="control-label"/>
diff --git a/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
index ef775c3e1..6f937b499 100644
--- a/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
@@ -1,9 +1,7 @@
-using Grand.Business.Core.Interfaces.Catalog.Directory;
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Utilities.Common.Security;
-using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Infrastructure;
using Grand.Web.Admin.Models.Customers;
@@ -19,13 +17,12 @@ public class OnlineCustomerController : BaseAdminController
#region Constructors
public OnlineCustomerController(ICustomerService customerService,
- IGeoLookupService geoLookupService, IDateTimeService dateTimeService,
+ IDateTimeService dateTimeService,
CustomerSettings customerSettings,
ITranslationService translationService,
IWorkContext workContext)
{
_customerService = customerService;
- _geoLookupService = geoLookupService;
_dateTimeService = dateTimeService;
_customerSettings = customerSettings;
_translationService = translationService;
@@ -37,7 +34,6 @@ public class OnlineCustomerController : BaseAdminController
#region Fields
private readonly ICustomerService _customerService;
- private readonly IGeoLookupService _geoLookupService;
private readonly IDateTimeService _dateTimeService;
private readonly CustomerSettings _customerSettings;
private readonly ITranslationService _translationService;
@@ -67,7 +63,6 @@ public class OnlineCustomerController : BaseAdminController
Id = x.Id,
CustomerInfo = !string.IsNullOrEmpty(x.Email) ? x.Email : _translationService.GetResource("Admin.Customers.Guest"),
LastIpAddress = x.LastIpAddress,
- Location = _geoLookupService.CountryName(x.LastIpAddress),
LastActivityDate = _dateTimeService.ConvertToUserTime(x.LastActivityDateUtc, DateTimeKind.Utc),
LastVisitedPage = _customerSettings.StoreLastVisitedPage ? x.LastVisitedPage : _translationService.GetResource("Admin.Dashboards.OnlineCustomers.Fields.LastVisitedPage.Disabled")
};
diff --git a/src/Web/Grand.Web.Admin/Models/Customers/OnlineCustomerModel.cs b/src/Web/Grand.Web.Admin/Models/Customers/OnlineCustomerModel.cs
index b5f0e0497..16a4d178b 100644
--- a/src/Web/Grand.Web.Admin/Models/Customers/OnlineCustomerModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Customers/OnlineCustomerModel.cs
@@ -11,9 +11,6 @@ public class OnlineCustomerModel : BaseEntityModel
[GrandResourceDisplayName("Admin.Dashboards.OnlineCustomers.Fields.IPAddress")]
public string LastIpAddress { get; set; }
- [GrandResourceDisplayName("Admin.Dashboards.OnlineCustomers.Fields.Location")]
- public string Location { get; set; }
-
[GrandResourceDisplayName("Admin.Dashboards.OnlineCustomers.Fields.LastActivityDate")]
public DateTime LastActivityDate { get; set; }
diff --git a/src/Web/Grand.Web.Admin/Models/Tax/TaxSettingsModel.cs b/src/Web/Grand.Web.Admin/Models/Tax/TaxSettingsModel.cs
index d8746f0e9..68e3dcae9 100644
--- a/src/Web/Grand.Web.Admin/Models/Tax/TaxSettingsModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Tax/TaxSettingsModel.cs
@@ -81,9 +81,6 @@ public class TaxSettingsModel : BaseModel
[GrandResourceDisplayName("Admin.Configuration.Tax.Settings.EuVatAssumeValid")]
public bool EuVatAssumeValid { get; set; }
- [GrandResourceDisplayName("Admin.Configuration.Tax.Settings.GetCountryByIPAddress")]
- public bool GetCountryByIPAddress { get; set; }
-
[GrandResourceDisplayName("Admin.Configuration.Tax.Settings.CalculateRoundPrice")]
public int CalculateRoundPrice { get; set; } = 2;
diff --git a/src/Web/Grand.Web/App_Data/GeoLite2-Country.mmdb b/src/Web/Grand.Web/App_Data/GeoLite2-Country.mmdb
deleted file mode 100644
index 6948a5244..000000000
Binary files a/src/Web/Grand.Web/App_Data/GeoLite2-Country.mmdb and /dev/null differ
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
index d1d6480f7..ea24e0a36 100644
--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
@@ -4962,9 +4962,6 @@
<Resource Name="Admin.Configuration.Tax.Settings.ForceTaxExclusionFromOrderSubtotal" Area="Admin">
<Value>Force tax exclusion from order subtotal</Value>
</Resource>
- <Resource Name="Admin.Configuration.Tax.Settings.GetCountryByIPAddress" Area="Admin">
- <Value>Get country by customer IP address</Value>
- </Resource>
<Resource Name="Admin.Configuration.Tax.Settings.HideTaxInOrderSummary" Area="Admin">
<Value>Hide tax in order summary</Value>
</Resource>
@@ -6837,9 +6834,6 @@
<Resource Name="Admin.Dashboards.OnlineCustomers.Fields.LastVisitedPage.Disabled" Area="Admin">
<Value>"Store last visited page" setting is disabled</Value>
</Resource>
- <Resource Name="Admin.Dashboards.OnlineCustomers.Fields.Location" Area="Admin">
- <Value>Location</Value>
- </Resource>
<Resource Name="admin.documents.document.account" Area="Admin">
<Value>Accounting Information</Value>
</Resource>