94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Nop.Core;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
|
using Nop.Services.Cms;
|
|
using Nop.Services.Logging;
|
|
using Nop.Web.Framework.Components;
|
|
using Nop.Web.Framework.Infrastructure;
|
|
using Nop.Web.Models.Catalog;
|
|
|
|
namespace Nop.Plugin.Misc.AuctionPlugin.Components;
|
|
|
|
public class AuctionViewComponent : NopViewComponent
|
|
{
|
|
#region Fields
|
|
|
|
protected readonly ILogger _logger;
|
|
protected readonly IWidgetPluginManager _widgetPluginManager;
|
|
protected readonly IWorkContext _workContext;
|
|
protected readonly AuctionSettings _auctionSettings;
|
|
|
|
#endregion
|
|
|
|
#region Ctor
|
|
|
|
public AuctionViewComponent(ILogger logger,
|
|
IWidgetPluginManager widgetPluginManager,
|
|
IWorkContext workContext,
|
|
AuctionSettings auctionSettings)
|
|
{
|
|
_logger = logger;
|
|
_widgetPluginManager = widgetPluginManager;
|
|
_workContext = workContext;
|
|
_auctionSettings = auctionSettings;
|
|
}
|
|
|
|
#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("Auction widget called");
|
|
|
|
//ensure that a 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);
|
|
|
|
if (string.IsNullOrEmpty(_auctionSettings.SomeText))
|
|
{
|
|
await _logger.ErrorAsync("Message error: message is not set", customer: customer);
|
|
return Content(string.Empty);
|
|
}
|
|
|
|
////display this on the checkout pages only
|
|
//if (ViewData.TemplateInfo.HtmlFieldPrefix != What3wordsDefaults.BillingAddressPrefix &&
|
|
// ViewData.TemplateInfo.HtmlFieldPrefix != What3wordsDefaults.ShippingAddressPrefix)
|
|
//{
|
|
// return Content(string.Empty);
|
|
//}
|
|
var model = new AuctionPublicInfoModel();
|
|
|
|
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsBottom))
|
|
{
|
|
|
|
model.Message = $"Auction plugin is active, setting = {_auctionSettings.SomeText}, productId = {((ProductDetailsModel)additionalData).Name}";
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
model.Message = _auctionSettings.SomeText;
|
|
|
|
}
|
|
|
|
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicInfo.cshtml", model);
|
|
|
|
}
|
|
|
|
#endregion
|
|
} |