using Microsoft.AspNetCore.Mvc; using Nop.Core; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Services; 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; AuctionService _auctionService; protected readonly AuctionSettings _auctionSettings; #endregion #region Ctor public AuctionViewComponent(ILogger logger, IWidgetPluginManager widgetPluginManager, IWorkContext workContext, AuctionService auctionService, AuctionSettings auctionSettings) { _logger = logger; _widgetPluginManager = widgetPluginManager; _workContext = workContext; _auctionService = auctionService; _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) { //await _logger.InformationAsync("Auction widget called"); //ensure that a widget is active and enabled var customer = await _workContext.GetCurrentCustomerAsync(); var currency = await _workContext.GetWorkingCurrencyAsync(); //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); //} if (!widgetZone.Equals(PublicWidgetZones.ProductBoxAddinfoBefore)) { return Content(string.Empty); } var productId = ((ProductOverviewModel)additionalData).Id; //model.ProductId = productId; var productToAuctionDtoMappings = await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId); if (productToAuctionDtoMappings.Count == 0) { return Content(string.Empty); } var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuctionDtoMappings.FirstOrDefault()!.AuctionId, false, false)); auctionDto.ProductToAuctionDtos.AddRange(productToAuctionDtoMappings); var model = new AuctionPublicInfoModel(auctionDto); model.WorkingCurrencyCode = currency.CurrencyCode; model.WorkingCurrencyRate = currency.Rate; //model.ProductToAuctionMappingId = productToAuctionMapping.Id; //var auction = await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuctionMapping.Id); //model.StartDate = auction.StartDateUtc; //AuctionStatus status = productToAuctionMapping.AuctionStatus; //model.IsActive = status.HasFlag(AuctionStatus.Active); //bool isFirstWarning = status.HasFlag(AuctionStatus.FirstWarning); return View("~/Plugins/Misc.AuctionPlugin/Views/PublicInfo.cshtml", model); } #endregion }