widgets basic setup

This commit is contained in:
Adam 2024-11-13 20:59:27 +01:00
parent cf33930077
commit ae6f4bc7e8
7 changed files with 53 additions and 31 deletions

View File

@ -92,7 +92,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
model.Body = singleAnnouncement.Body;
model.IsActive = singleAnnouncement.IsActive;
return View("~/Plugins/Widget.LiveAnnouncement/Views/LiveAnnouncementView/Announcement.cshtml", model);
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/Announcement.cshtml", model);
}
@ -107,7 +107,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
public IActionResult AnnouncementList()
{
var model = new AnnouncementViewModel();
return View("~/Plugins/Misc.Auction/Areas/Admin/Views/AnnouncementList.cshtml", model);
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/AnnouncementList.cshtml", model);
}
//[HttpPost]

View File

@ -10,7 +10,7 @@ public static class AuctionDefaults
/// <summary>
/// Gets the system name
/// </summary>
public static string SystemName => "Misc.AuctionPlugin";
public static string SystemName => "AuctionPlugin";
/// <summary>
/// Gets the user agent used to request third-party services

View File

@ -99,7 +99,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin
{
ArgumentNullException.ThrowIfNull(widgetZone);
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop))
if (widgetZone.Equals(PublicWidgetZones.ProductPriceTop))
{
return typeof(AuctionPublicViewComponent);
}
@ -116,11 +116,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin
{
return Task.FromResult<IList<string>>(new List<string>
{
PublicWidgetZones.ProductDetailsOverviewTop,
PublicWidgetZones.OrderSummaryBillingAddress,
PublicWidgetZones.ProductPriceTop,
PublicWidgetZones.ProductDetailsBottom,
AdminWidgetZones.OrderBillingAddressDetailsBottom,
AdminWidgetZones.OrderShippingAddressDetailsBottom
//AdminWidgetZones.OrderBillingAddressDetailsBottom,
//AdminWidgetZones.OrderShippingAddressDetailsBottom
});
}

View File

@ -3,6 +3,7 @@ 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;
@ -20,6 +21,7 @@ public class AuctionPublicViewComponent : NopViewComponent
protected readonly IWidgetPluginManager _widgetPluginManager;
protected readonly IWorkContext _workContext;
protected readonly AuctionSettings _auctionSettings;
protected readonly ILogger _logger;
#endregion
@ -29,13 +31,15 @@ public class AuctionPublicViewComponent : NopViewComponent
IGenericAttributeService genericAttributeService,
IWidgetPluginManager widgetPluginManager,
IWorkContext workContext,
AuctionSettings auctionSettings)
AuctionSettings auctionSettings,
ILogger logger)
{
_addressService = addressService;
_genericAttributeService = genericAttributeService;
_widgetPluginManager = widgetPluginManager;
_workContext = workContext;
_auctionSettings = auctionSettings;
_logger = logger;
}
#endregion
@ -53,25 +57,41 @@ public class AuctionPublicViewComponent : NopViewComponent
/// </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);
if (!_auctionSettings.Enabled)
return Content(string.Empty);
await _logger.InformationAsync("WidgetViewComponent widget active");
//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;
await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}");
return View("~/Plugins/Widgets.What3words/Views/PublicProductBidBox.cshtml", productId.ToString());
//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

View File

@ -49,16 +49,16 @@ public class AuctionViewComponent : NopViewComponent
/// </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 (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
// return Content(string.Empty);
if (!_auctionSettings.Enabled)
return Content(string.Empty);
//if (!_auctionSettings.Enabled)
// return Content(string.Empty);
if (string.IsNullOrEmpty(_auctionSettings.SomeText))
{
@ -74,7 +74,7 @@ public class AuctionViewComponent : NopViewComponent
//}
var model = new AuctionPublicInfoModel();
if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsTop))
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsBottom))
{
model.Message = $"Auction plugin is active, setting = {_auctionSettings.SomeText}, productId = {((ProductDetailsModel)additionalData).Name}";
@ -87,7 +87,7 @@ public class AuctionViewComponent : NopViewComponent
}
return View("~/Plugins/Widgets.AuctionPlugin/Views/PublicInfo.cshtml", model);
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicInfo.cshtml", model);
}

View File

@ -1,8 +1,9 @@
@model AuctionPublicInfoModel
<div>
<label for="w3w">@T("Plugins.Widgets.AuctionPLugin.Label"):</label>
<div class="bg-dark">
<h3>Auction viewcomponent</h3>
<label for="w3w">@T("Plugins.Misc.AuctionPLugin.Label"):</label>
<div class="">
<p>@Model.Message</p>
<p>General widget info: @Model.Message</p>
</div>
</div>

View File

@ -1,11 +1,12 @@
@model string
<li class="custom-value">
<div class="bg-dark">
<h3>Auction Public Viewcomponent</h3>
<span class="label">
@T("Plugins.Misc.AuctionPlugin.BidBox.Field.Label"):
</span>
<span class="value">
@(Model)
</span>
</li>
</div>