using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Routing;
using Nop.Core;
using Nop.Core.Domain.Cms;
using Nop.Services.Cms;
using Nop.Services.Common;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Messages;
using Nop.Services.Plugins;
using Nop.Web.Framework.Menu;
namespace Nop.Plugin.Misc.NopCliGeneric
{
///
/// Represents the NopCliGeneric plugin
///
public class NopCliGenericPlugin : BasePlugin, IMiscPlugin, IWidgetPlugin, IAdminMenuPlugin
{
#region Fields
private readonly ILocalizationService _localizationService;
private readonly ISettingService _settingService;
private readonly IWebHelper _webHelper;
private readonly IMessageTemplateService _messageTemplateService;
private readonly WidgetSettings _widgetSettings;
#endregion
#region Ctor
public NopCliGenericPlugin(
ILocalizationService localizationService,
ISettingService settingService,
IWebHelper webHelper,
IMessageTemplateService messageTemplateService,
WidgetSettings widgetSettings)
{
_localizationService = localizationService;
_settingService = settingService;
_webHelper = webHelper;
_widgetSettings = widgetSettings;
_messageTemplateService = messageTemplateService;
}
#endregion
#region Methods
///
/// Gets widget zones where this widget should be rendered
///
/// Widget zones
public IList GetWidgetZones()
{
return new List { };
}
///
/// Gets a name of a view component for displaying widget
///
/// Name of the widget zone
/// View component name
public string GetWidgetViewComponentName(string widgetZone)
{
return NopCliGenericDefaults.TRACKING_VIEW_COMPONENT_NAME;
}
///
/// Gets a configuration page URL
///
public override string GetConfigurationPageUrl()
{
return $"{_webHelper.GetStoreLocation()}Admin/NopCliGeneric/Configure";
}
///
/// Install the plugin
///
public override void Install()
{
//settings
_settingService.SaveSetting(new NopCliGenericSettings { });
if (!_widgetSettings.ActiveWidgetSystemNames.Contains(NopCliGenericDefaults.SystemName))
{
_widgetSettings.ActiveWidgetSystemNames.Add(NopCliGenericDefaults.SystemName);
_settingService.SaveSetting(_widgetSettings);
}
//locales
_localizationService.AddPluginLocaleResource(new Dictionary
{
["plugins.misc.NopCliGeneric"] = "NopCliGeneric store settings",
["plugins.Misc.NopCliGeneric.Fields.NopCliGenericToName"] = "To Name"
});
base.Install();
}
///
/// Uninstall the plugin
///
public override void Uninstall()
{
//settings
if (_widgetSettings.ActiveWidgetSystemNames.Contains(NopCliGenericDefaults.SystemName))
{
_widgetSettings.ActiveWidgetSystemNames.Remove(NopCliGenericDefaults.SystemName);
_settingService.SaveSetting(_widgetSettings);
}
_settingService.DeleteSetting();
//locales
_localizationService.DeletePluginLocaleResources("Plugins.Misc.NopCliGeneric");
base.Uninstall();
}
#endregion
public void ManageSiteMap(SiteMapNode rootNode)
{
var menuItem = new SiteMapNode()
{
SystemName = "Misc.NopCliGeneric",
Title = "NopCliGeneric Settings",
ControllerName = "NopCliGeneric",
ActionName = "Configure",
IconClass = "fa-dot-circle-o",
Visible = true,
RouteValues = new RouteValueDictionary() { { "area", "Admin" } },
};
var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Configuration");
if(pluginNode != null)
pluginNode.ChildNodes.Add(menuItem);
else
rootNode.ChildNodes.Add(menuItem);
}
///
/// Gets a value indicating whether to hide this plugin on the widget list page in the admin area
///
public bool HideInWidgetList => true;
}
}