98 lines
3.3 KiB
C#
98 lines
3.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Nop.Core;
|
|
using Nop.Plugin.Misc.AuctionPlugin;
|
|
using Nop.Services.Cms;
|
|
using Nop.Services.Common;
|
|
using Nop.Services.Logging;
|
|
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;
|
|
protected readonly ILogger _logger;
|
|
|
|
#endregion
|
|
|
|
#region Ctor
|
|
|
|
public AuctionPublicViewComponent(IAddressService addressService,
|
|
IGenericAttributeService genericAttributeService,
|
|
IWidgetPluginManager widgetPluginManager,
|
|
IWorkContext workContext,
|
|
AuctionSettings auctionSettings,
|
|
ILogger logger)
|
|
{
|
|
_addressService = addressService;
|
|
_genericAttributeService = genericAttributeService;
|
|
_widgetPluginManager = widgetPluginManager;
|
|
_workContext = workContext;
|
|
_auctionSettings = auctionSettings;
|
|
_logger = logger;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Invoke the widget view component
|
|
/// </summary>
|
|
/// <param name="widgetZone">Widget zone</param>
|
|
/// <param name="additionalData">Additional parameters</param>
|
|
/// <returns>
|
|
/// A task that represents the asynchronous operation
|
|
/// The task result contains the view component result
|
|
/// </returns>
|
|
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
|
|
{
|
|
await _logger.InformationAsync("WidgetViewComponent called");
|
|
|
|
//ensure that what3words widget is active and enabled
|
|
var customer = await _workContext.GetCurrentCustomerAsync();
|
|
await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}");
|
|
|
|
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
|
|
return Content(string.Empty);
|
|
|
|
await _logger.InformationAsync("WidgetViewComponent widget active");
|
|
|
|
//if (!_auctionSettings.Enabled)
|
|
// return Content(string.Empty);
|
|
|
|
var productDetailsModel = additionalData as ProductDetailsModel;
|
|
|
|
await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}");
|
|
|
|
//if (productDetailsModel is null)
|
|
//{
|
|
|
|
// await _logger.InformationAsync("WidgetViewComponent productdetailsmodel is null");
|
|
// return Content(string.Empty);
|
|
//}
|
|
|
|
if (!widgetZone.Equals(PublicWidgetZones.ProductPriceTop))
|
|
{
|
|
await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}");
|
|
return Content(string.Empty);
|
|
}
|
|
|
|
await _logger.InformationAsync("WidgetViewComponent called II");
|
|
|
|
|
|
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productDetailsModel.Id.ToString());
|
|
}
|
|
|
|
#endregion
|
|
} |