Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

PickupPluginManager.cs

using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Shipping;
using Nop.Services.Customers;
using Nop.Services.Plugins;

namespace Nop.Services.Shipping.Pickup;

/// 
/// Represents a pickup point plugin manager implementation
/// 
public partial class PickupPluginManager : PluginManager, IPickupPluginManager
{
    #region Fields

    protected readonly ShippingSettings _shippingSettings;

    #endregion

    #region Ctor

    public PickupPluginManager(ICustomerService customerService,
        IPluginService pluginService,
        ShippingSettings shippingSettings) : base(customerService, pluginService)
    {
        _shippingSettings = shippingSettings;
    }

    #endregion

    #region Methods

    /// 
    /// Load active pickup point providers
    /// 
    /// Filter by customer; pass null to load all plugins
    /// Filter by store; pass 0 to load all plugins
    /// Filter by pickup point provider system name; pass null to load all plugins
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the list of active pickup point providers
    /// 
    public virtual async Task> LoadActivePluginsAsync(Customer customer = null, int storeId = 0, string systemName = null)
    {
        var pickupPointProviders = await LoadActivePluginsAsync(_shippingSettings.ActivePickupPointProviderSystemNames, customer, storeId);

        //filter by passed system name
        if (!string.IsNullOrEmpty(systemName))
        {
            pickupPointProviders = pickupPointProviders
                .Where(provider => provider.PluginDescriptor.SystemName.Equals(systemName, StringComparison.InvariantCultureIgnoreCase))
                .ToList();
        }

        return pickupPointProviders;
    }

    /// 
    /// Check whether the passed pickup point provider is active
    /// 
    /// Pickup point provider to check
    /// Result
    public virtual bool IsPluginActive(IPickupPointProvider pickupPointProvider)
    {
        return IsPluginActive(pickupPointProvider, _shippingSettings.ActivePickupPointProviderSystemNames);
    }

    /// 
    /// Check whether the pickup point provider with the passed system name is active
    /// 
    /// System name of pickup point provider 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 pickupPointProvider = await LoadPluginBySystemNameAsync(systemName, customer, storeId);
        return IsPluginActive(pickupPointProvider);
    }

    #endregion
}