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.

Changes in structure IShippingRateCalculationProvider plugins, move away from viewcomponent, now use Controllers

support11ff9929e704
diff --git a/src/Business/Grand.Business.Core/Interfaces/Checkout/Shipping/IShippingRateCalculationProvider.cs b/src/Business/Grand.Business.Core/Interfaces/Checkout/Shipping/IShippingRateCalculationProvider.cs
index 2e5be26e1..7b11b0b7f 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Checkout/Shipping/IShippingRateCalculationProvider.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Checkout/Shipping/IShippingRateCalculationProvider.cs
@@ -46,10 +46,10 @@ namespace Grand.Business.Core.Interfaces.Checkout.Shipping
Task<IList<string>> ValidateShippingForm(IFormCollection form);
/// <summary>
- /// Gets a view component for displaying plugin ("shipping" checkout step)
+ /// Gets a route name for displaying plugin ("shipping" checkout step)
/// </summary>
/// <param name="viewComponentName">View component name</param>
- Task<string> GetPublicViewComponentName();
+ Task<string> GetControllerRouteName();
}
}
diff --git a/src/Plugins/Shipping.ByWeight/ByWeightShippingProvider.cs b/src/Plugins/Shipping.ByWeight/ByWeightShippingProvider.cs
index 20e44bd2d..ca84e9491 100644
--- a/src/Plugins/Shipping.ByWeight/ByWeightShippingProvider.cs
+++ b/src/Plugins/Shipping.ByWeight/ByWeightShippingProvider.cs
@@ -312,7 +312,7 @@ namespace Shipping.ByWeight
return await Task.FromResult(new List<string>());
}
- public async Task<string> GetPublicViewComponentName()
+ public async Task<string> GetControllerRouteName()
{
return await Task.FromResult("");
}
diff --git a/src/Plugins/Shipping.FixedRateShipping/FixedRateShippingProvider.cs b/src/Plugins/Shipping.FixedRateShipping/FixedRateShippingProvider.cs
index 0d5d468cc..333a120f4 100644
--- a/src/Plugins/Shipping.FixedRateShipping/FixedRateShippingProvider.cs
+++ b/src/Plugins/Shipping.FixedRateShipping/FixedRateShippingProvider.cs
@@ -123,7 +123,7 @@ namespace Shipping.FixedRateShipping
return await Task.FromResult(new List<string>());
}
- public async Task<string> GetPublicViewComponentName()
+ public async Task<string> GetControllerRouteName()
{
return await Task.FromResult("");
}
diff --git a/src/Plugins/Shipping.ShippingPoint/Components/SelectedShippingPointViewComponent.cs b/src/Plugins/Shipping.ShippingPoint/Components/SelectedShippingPointViewComponent.cs
deleted file mode 100644
index f21278990..000000000
--- a/src/Plugins/Shipping.ShippingPoint/Components/SelectedShippingPointViewComponent.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Rendering;
-using Shipping.ShippingPoint.Services;
-
-namespace Shipping.ShippingPoint.Components
-{
- [ViewComponent(Name = "ShippingPoint")]
- public class SelectedShippingPointViewComponent : ViewComponent
- {
- private readonly ITranslationService _translationService;
- private readonly IShippingPointService _shippingPointService;
- private readonly IWorkContext _workContext;
-
- public SelectedShippingPointViewComponent(ITranslationService translationService,
- IShippingPointService shippingPointService, IWorkContext workContext)
- {
- _translationService = translationService;
- _shippingPointService = shippingPointService;
- _workContext = workContext;
- }
- public async Task<IViewComponentResult> InvokeAsync(string shippingOption)
- {
- var parameter = shippingOption.Split(new[] { "___" }, StringSplitOptions.RemoveEmptyEntries)[0];
-
- if (parameter == _translationService.GetResource("Shipping.ShippingPoint.PluginName"))
- {
- var shippingPoints = await _shippingPointService.GetAllStoreShippingPoint(_workContext.CurrentStore.Id);
-
- var shippingPointsModel = new List<SelectListItem>();
- shippingPointsModel.Add(new SelectListItem() { Value = "", Text = _translationService.GetResource("Shipping.ShippingPoint.SelectShippingOption") });
-
- foreach (var shippingPoint in shippingPoints)
- {
- shippingPointsModel.Add(new SelectListItem() { Value = shippingPoint.Id, Text = shippingPoint.ShippingPointName });
- }
-
- return View(shippingPointsModel);
- }
- return Content("ShippingPointController: given Shipping Option doesn't exist");
-
- }
- }
-}
diff --git a/src/Plugins/Shipping.ShippingPoint/Controllers/SelectedShippingPointController.cs b/src/Plugins/Shipping.ShippingPoint/Controllers/SelectedShippingPointController.cs
index cafdf4837..331891f70 100644
--- a/src/Plugins/Shipping.ShippingPoint/Controllers/SelectedShippingPointController.cs
+++ b/src/Plugins/Shipping.ShippingPoint/Controllers/SelectedShippingPointController.cs
@@ -1,7 +1,9 @@
using Grand.Business.Core.Interfaces.Catalog.Prices;
using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Infrastructure;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Rendering;
using Shipping.ShippingPoint.Models;
using Shipping.ShippingPoint.Services;
@@ -14,19 +16,22 @@ namespace Shipping.ShippingPoint.Controllers
private readonly IPriceFormatter _priceFormatter;
private readonly IWorkContext _workContext;
private readonly ICurrencyService _currencyService;
+ private readonly ITranslationService _translationService;
public SelectedShippingPointController(
IShippingPointService shippingPointService,
ICountryService countryService,
IPriceFormatter priceFormatter,
IWorkContext workContext,
- ICurrencyService currencyService)
+ ICurrencyService currencyService,
+ ITranslationService translationService)
{
_shippingPointService = shippingPointService;
_countryService = countryService;
_priceFormatter = priceFormatter;
_workContext = workContext;
_currencyService = currencyService;
+ _translationService = translationService;
}
public async Task<IActionResult> Get(string shippingOptionId)
{
@@ -50,5 +55,27 @@ namespace Shipping.ShippingPoint.Controllers
}
return Content("ShippingPointController: given Shipping Option doesn't exist");
}
+
+ public async Task<IActionResult> Points(string shippingOption)
+ {
+ var parameter = shippingOption.Split(new[] { "___" }, StringSplitOptions.RemoveEmptyEntries)[0];
+
+ if (parameter == _translationService.GetResource("Shipping.ShippingPoint.PluginName"))
+ {
+ var shippingPoints = await _shippingPointService.GetAllStoreShippingPoint(_workContext.CurrentStore.Id);
+
+ var shippingPointsModel = new List<SelectListItem>();
+ shippingPointsModel.Add(new SelectListItem() { Value = "", Text = _translationService.GetResource("Shipping.ShippingPoint.SelectShippingOption") });
+
+ foreach (var shippingPoint in shippingPoints)
+ {
+ shippingPointsModel.Add(new SelectListItem() { Value = shippingPoint.Id, Text = shippingPoint.ShippingPointName });
+ }
+
+ return View(shippingPointsModel);
+ }
+ return Content("ShippingPointController: given Shipping Option doesn't exist");
+
+ }
}
}
diff --git a/src/Plugins/Shipping.ShippingPoint/EndpointProvider.cs b/src/Plugins/Shipping.ShippingPoint/EndpointProvider.cs
new file mode 100644
index 000000000..628c4d308
--- /dev/null
+++ b/src/Plugins/Shipping.ShippingPoint/EndpointProvider.cs
@@ -0,0 +1,19 @@
+using Grand.Infrastructure.Endpoints;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Routing;
+
+namespace Shipping.ShippingPoint
+{
+ public partial class EndpointProvider : IEndpointProvider
+ {
+ public void RegisterEndpoint(IEndpointRouteBuilder endpointRouteBuilder)
+ {
+ endpointRouteBuilder.MapControllerRoute("Plugins.ShippingPoint.Points",
+ "Plugins/SelectedShippingPoint/Points",
+ new { controller = "SelectedShippingPoint", action = "Points" }
+ );
+ }
+ public int Priority => 0;
+
+ }
+}
diff --git a/src/Plugins/Shipping.ShippingPoint/Manifest.cs b/src/Plugins/Shipping.ShippingPoint/Manifest.cs
index 7404fa8b8..27c4a8a13 100644
--- a/src/Plugins/Shipping.ShippingPoint/Manifest.cs
+++ b/src/Plugins/Shipping.ShippingPoint/Manifest.cs
@@ -8,5 +8,5 @@ using Shipping.ShippingPoint;
SystemName = ShippingPointRateDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
- Version = "1.01"
+ Version = "1.02"
)]
\ No newline at end of file
diff --git a/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs b/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
index b225c186d..243c23e7c 100644
--- a/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
+++ b/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
@@ -159,9 +159,9 @@ namespace Shipping.ShippingPoint
return new List<string>();
}
- public async Task<string> GetPublicViewComponentName()
+ public async Task<string> GetControllerRouteName()
{
- return await Task.FromResult("ShippingPoint");
+ return await Task.FromResult("Plugins.ShippingPoint.Points");
}
public ShippingRateCalculationType ShippingRateCalculationType => ShippingRateCalculationType.Off;
diff --git a/src/Plugins/Shipping.ShippingPoint/Views/Shared/Components/ShippingPoint/Default.cshtml b/src/Plugins/Shipping.ShippingPoint/Views/SelectedShippingPoint/Points.cshtml
similarity index 95%
rename from src/Plugins/Shipping.ShippingPoint/Views/Shared/Components/ShippingPoint/Default.cshtml
rename to src/Plugins/Shipping.ShippingPoint/Views/SelectedShippingPoint/Points.cshtml
index 0759e8b12..d9f6a8827 100644
--- a/src/Plugins/Shipping.ShippingPoint/Views/Shared/Components/ShippingPoint/Default.cshtml
+++ b/src/Plugins/Shipping.ShippingPoint/Views/SelectedShippingPoint/Points.cshtml
@@ -1,4 +1,7 @@
@model List<SelectListItem>
+@{
+ Layout = "";
+}
<div class="script-tag">
<script>
function renderShippingOptionInfo(param) {
diff --git a/src/Web/Grand.Web/Controllers/CheckoutController.cs b/src/Web/Grand.Web/Controllers/CheckoutController.cs
index 9070427b1..2733d52dd 100644
--- a/src/Web/Grand.Web/Controllers/CheckoutController.cs
+++ b/src/Web/Grand.Web/Controllers/CheckoutController.cs
@@ -383,11 +383,11 @@ namespace Grand.Web.Controllers
public virtual async Task<IActionResult> GetShippingFormPartialView(string shippingOption)
{
- var viewcomponent = await GetShippingComputation(shippingOption).GetPublicViewComponentName();
- if (string.IsNullOrEmpty(viewcomponent))
+ var routeName = await GetShippingComputation(shippingOption).GetControllerRouteName();
+ if (string.IsNullOrEmpty(routeName))
return Content("");
- return ViewComponent(viewcomponent, new { shippingOption = shippingOption });
+ return RedirectToRoute(routeName, new { shippingOption });
}
[NonAction]