using Microsoft.AspNetCore.Mvc; using Nop.Services.Security; using Nop.Services.Tax; using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; namespace Nop.Plugin.Tax.Avalara.Components; /// /// Represents a view component to render the button on a product list view /// public class ExportItemsViewComponent : NopViewComponent { #region Fields protected readonly IPermissionService _permissionService; protected readonly ITaxPluginManager _taxPluginManager; #endregion #region Ctor public ExportItemsViewComponent(IPermissionService permissionService, ITaxPluginManager taxPluginManager) { _permissionService = permissionService; _taxPluginManager = taxPluginManager; } #endregion #region Methods /// /// Invoke the widget view component /// /// Widget zone /// Additional parameters /// /// A task that represents the asynchronous operation /// The task result contains the view component result /// public async Task InvokeAsync(string widgetZone, object additionalData) { //ensure that Avalara tax provider is active if (!await _taxPluginManager.IsPluginActiveAsync(AvalaraTaxDefaults.SystemName)) return Content(string.Empty); if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageTaxSettings)) return Content(string.Empty); //ensure that it's a proper widget zone if (!widgetZone.Equals(AdminWidgetZones.ProductListButtons)) return Content(string.Empty); return View("~/Plugins/Tax.Avalara/Views/Product/ExportItems.cshtml"); } #endregion }