94 lines
2.4 KiB
C#
94 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Routing;
|
|
using Nop.Core;
|
|
using Nop.Services.Common;
|
|
using Nop.Services.Plugins;
|
|
using Nop.Services.Security;
|
|
using Nop.Web.Framework;
|
|
using Nop.Web.Framework.Menu;
|
|
|
|
namespace Nop.Plugin.Misc.WebApi.Frontend;
|
|
|
|
/// <summary>
|
|
/// Represents the Web API frontend plugin
|
|
/// </summary>
|
|
public class WebApiFrontendPlugin : BasePlugin, IAdminMenuPlugin, IMiscPlugin
|
|
{
|
|
#region Fields
|
|
|
|
protected readonly IPermissionService _permissionService;
|
|
protected readonly IWebHelper _webHelper;
|
|
|
|
#endregion
|
|
|
|
#region Ctor
|
|
|
|
public WebApiFrontendPlugin(IPermissionService permissionService,
|
|
IWebHelper webHelper)
|
|
{
|
|
_permissionService = permissionService;
|
|
_webHelper = webHelper;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Gets a configuration page URL
|
|
/// </summary>
|
|
public override string GetConfigurationPageUrl()
|
|
{
|
|
return $"{_webHelper.GetStoreLocation()}Admin/WebApiFrontend/Configure";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Install the plugin
|
|
/// </summary>
|
|
/// <returns>A task that represents the asynchronous operation</returns>
|
|
public override async Task InstallAsync()
|
|
{
|
|
await base.InstallAsync();
|
|
}
|
|
|
|
public async Task ManageSiteMapAsync(SiteMapNode rootNode)
|
|
{
|
|
if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePlugins))
|
|
return;
|
|
|
|
var config = rootNode.ChildNodes.FirstOrDefault(node => node.SystemName.Equals("Configuration"));
|
|
if (config == null)
|
|
return;
|
|
|
|
var plugins = config.ChildNodes.FirstOrDefault(node => node.SystemName.Equals("Local plugins"));
|
|
|
|
if (plugins == null)
|
|
return;
|
|
|
|
var index = config.ChildNodes.IndexOf(plugins);
|
|
|
|
if (index < 0)
|
|
return;
|
|
|
|
config.ChildNodes.Insert(index, new SiteMapNode
|
|
{
|
|
SystemName = "nopCommerce Web API plugin",
|
|
Title = "Web API",
|
|
ControllerName = "WebApiFrontend",
|
|
ActionName = "Configure",
|
|
IconClass = "far fa-dot-circle",
|
|
Visible = true,
|
|
RouteValues = new RouteValueDictionary { { "area", AreaNames.ADMIN } }
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Uninstall the plugin
|
|
/// </summary>
|
|
/// <returns>A task that represents the asynchronous operation</returns>
|
|
public override async Task UninstallAsync()
|
|
{
|
|
await base.UninstallAsync();
|
|
}
|
|
|
|
#endregion
|
|
} |