Webiant Logo Webiant Logo
  1. No results found.

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

TaxPluginManager.cs

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

namespace Nop.Services.Tax;

/// 
/// Represents a tax plugin manager implementation
/// 
public partial class TaxPluginManager : PluginManager, ITaxPluginManager
{
    #region Fields

    protected readonly TaxSettings _taxSettings;

    #endregion

    #region Ctor

    public TaxPluginManager(ICustomerService customerService,
        IPluginService pluginService,
        TaxSettings taxSettings) : base(customerService, pluginService)
    {
        _taxSettings = taxSettings;
    }

    #endregion

    #region Methods

    /// 
    /// Load primary active tax provider
    /// 
    /// 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 ax provider
    /// 
    public virtual async Task LoadPrimaryPluginAsync(Customer customer = null, int storeId = 0)
    {
        return await LoadPrimaryPluginAsync(_taxSettings.ActiveTaxProviderSystemName, customer, storeId);
    }

    /// 
    /// Check whether the passed tax provider is active
    /// 
    /// Tax provider to check
    /// Result
    public virtual bool IsPluginActive(ITaxProvider taxProvider)
    {
        return IsPluginActive(taxProvider, [_taxSettings.ActiveTaxProviderSystemName]);
    }

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

    #endregion
}