using Nop.Core;
using Nop.Services.Cms;
using Nop.Services.Plugins;
using System.Threading.Tasks;
using Nop.Services.Localization;
using System.Collections.Generic;
using Nop.Services.Configuration;
using Nop.Web.Framework.Infrastructure;
namespace Nop.Plugin.Widgets.NopCliGeneric
{
///
/// Plugin
///
public class WidgetsNopCliGenericPlugin : BasePlugin, IWidgetPlugin
{
private readonly ILocalizationService _localizationService;
private readonly ISettingService _settingService;
private readonly IWebHelper _webHelper;
public WidgetsNopCliGenericPlugin(ILocalizationService localizationService,
ISettingService settingService,
IWebHelper webHelper )
{
_localizationService = localizationService;
_settingService = settingService;
_webHelper = webHelper;
}
///
/// Gets widget zones where this widget should be rendered
///
/// Widget zones
public Task> GetWidgetZonesAsync()
{
return Task.FromResult>(new List { PublicWidgetZones.HomepageTop });
}
///
/// Gets a configuration page URL
///
public override string GetConfigurationPageUrl()
{
return $"{_webHelper.GetStoreLocation()}Admin/Widgets.NopCliGeneric/Configure";
}
///
/// Gets a name of a view component for displaying widget
///
/// Name of the widget zone
/// View component name
public string GetWidgetViewComponentName(string widgetZone)
{
return "WidgetsWidgetsNopCliGeneric";
}
///
/// Install plugin
///
public override async Task InstallAsync()
{
//settings
var settings = new WidgetsNopCliGenericSettings()
{
Property = "NopCliGeneric"
};
await _settingService.SaveSettingAsync(settings);
await _localizationService.AddLocaleResourceAsync(new Dictionary
{
["Plugins.Widgets.WidgetsNopCliGeneric.Property"] = "NopCliGeneric",
});
await base.InstallAsync();
}
///
/// Uninstall plugin
///
public override async Task UninstallAsync()
{
//settings
await _settingService.DeleteSettingAsync();
//locales
await _localizationService.DeleteLocaleResourceAsync("Plugins.Widgets.WidgetsNopCliGeneric");
await base.UninstallAsync();
}
///
/// Gets a value indicating whether to hide this plugin on the widget list page in the admin area
///
public bool HideInWidgetList => false;
}
}