using Nop.Core.Domain.Cms; using Nop.Core.Domain.Customers; using Nop.Services.Customers; using Nop.Services.Plugins; namespace Nop.Services.Cms; /// /// Represents a widget plugin manager implementation /// public partial class WidgetPluginManager : PluginManager, IWidgetPluginManager { #region Fields protected readonly WidgetSettings _widgetSettings; #endregion #region Ctor public WidgetPluginManager(ICustomerService customerService, IPluginService pluginService, WidgetSettings widgetSettings) : base(customerService, pluginService) { _widgetSettings = widgetSettings; } #endregion #region Methods /// /// Load active widgets /// /// Filter by customer; pass null to load all plugins /// Filter by store; pass 0 to load all plugins /// Widget zone; pass null to load all plugins /// /// A task that represents the asynchronous operation /// The task result contains the list of active widget /// public virtual async Task> LoadActivePluginsAsync(Customer customer = null, int storeId = 0, string widgetZone = null) { var widgets = await LoadActivePluginsAsync(_widgetSettings.ActiveWidgetSystemNames, customer, storeId); //filter by widget zone if (!string.IsNullOrEmpty(widgetZone)) widgets = await widgets.WhereAwait(async widget => (await widget.GetWidgetZonesAsync()).Contains(widgetZone, StringComparer.InvariantCultureIgnoreCase)).ToListAsync(); return widgets; } /// /// Check whether the passed widget is active /// /// Widget to check /// Result public virtual bool IsPluginActive(IWidgetPlugin widget) { return IsPluginActive(widget, _widgetSettings.ActiveWidgetSystemNames); } /// /// Check whether the widget with the passed system name is active /// /// System name of widget to check /// Filter by customer; pass null to load all plugins /// Filter by store; pass 0 to load all plugins /// /// A task that represents the asynchronous operation /// The task result contains the result /// public virtual async Task IsPluginActiveAsync(string systemName, Customer customer = null, int storeId = 0) { var widget = await LoadPluginBySystemNameAsync(systemName, customer, storeId); return IsPluginActive(widget); } #endregion }