using Microsoft.AspNetCore.Mvc; using Nop.Core; using Nop.Plugin.Misc.AuctionPlugin; using Nop.Services.Cms; using Nop.Services.Common; using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; using Nop.Web.Models.Catalog; using Nop.Web.Models.Order; using Nop.Web.Models.ShoppingCart; namespace Nop.Plugin.AuctionPlugin.Components; public class AuctionPublicViewComponent : NopViewComponent { #region Fields protected readonly IAddressService _addressService; protected readonly IGenericAttributeService _genericAttributeService; protected readonly IWidgetPluginManager _widgetPluginManager; protected readonly IWorkContext _workContext; protected readonly AuctionSettings _auctionSettings; #endregion #region Ctor public AuctionPublicViewComponent(IAddressService addressService, IGenericAttributeService genericAttributeService, IWidgetPluginManager widgetPluginManager, IWorkContext workContext, AuctionSettings auctionSettings) { _addressService = addressService; _genericAttributeService = genericAttributeService; _widgetPluginManager = widgetPluginManager; _workContext = workContext; _auctionSettings = auctionSettings; } #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 what3words widget is active and enabled var customer = await _workContext.GetCurrentCustomerAsync(); if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer)) return Content(string.Empty); if (!_auctionSettings.Enabled) return Content(string.Empty); var productDetailsModel = additionalData as ProductDetailsModel; if (productDetailsModel is null) return Content(string.Empty); var productId = 0; if (widgetZone.Equals(PublicWidgetZones.ProductDetailsTop)) productId = productDetailsModel.Id; return View("~/Plugins/Widgets.What3words/Views/PublicProductBidBox.cshtml", productId.ToString()); } #endregion }