diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index 8c5adf5..c041551 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -127,9 +127,12 @@ public class AuctionPublicViewComponent : NopViewComponent auctionId = valami.Id; } + var productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id); + productBidBoxViewModel.WidgetZone = widgetZone; productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue; productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue; + productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id; productBidBoxViewModel.AuctionId = auctionId; productBidBoxViewModel.CustomerId = customer.Id; productBidBoxViewModel.ProductId = productDetailsModel.Id; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js index 226cb05..ceb6f54 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js @@ -39,9 +39,16 @@ "hideMethod": "fadeOut" }); $('.toast-success').css("background-color", "#4caf50"); + + const publicProductBidBox = document.getElementById("publicProductBidBox"); + if (publicProductBidBox) { + refreshPublicBidBox(data); + } + }, auctionUpdateAlternate: function (data) { const widgetPriceElement = document.getElementById("WidgetPrice"); + if (widgetPriceElement) { widgetPriceElement.textContent = data.bidPrice; // Update the price console.log(`WidgetPrice updated to: ${data.bidPrice}`); @@ -49,20 +56,25 @@ console.warn("Element with ID 'WidgetPrice' not found in the DOM."); } }, - auctionUpdate: function (data) { - // Refresh the ViewComponent using AJAX - $.ajax({ - url: '/Auction/RefreshAuctionWidget', // Controller endpoint - method: 'GET', - success: function (response) { - //$('#auction-widget').html(response); // Update the DOM element - console.log("Auction widget refreshed!"); - }, - error: function (error) { - console.error("Error refreshing auction widget:", error); - } - }); - }, + //auctionUpdate: function (data) { + // // Refresh the ViewComponent using AJAX + // $.ajax({ + // url: '/Auction/RefreshAuctionWidget', // Controller endpoint + // type: 'POST', + // contentType: 'application/json', + // data: JSON.stringify({ + // WidgetZone: data.WidgetZone, + // ProductId: data.ProductId + // }), + // success: function (response) { + // //$('#auction-widget').html(response); // Update the DOM element + // console.log("Auction widget refreshed!"); + // }, + // error: function (error) { + // console.error("Error refreshing auction widget:", error); + // } + // }); + //}, // Add more handlers as needed default: function (data) { diff --git a/Nop.Plugin.Misc.AuctionPlugin/Hubs/Messages/BidNotificationMessage.cs b/Nop.Plugin.Misc.AuctionPlugin/Hubs/Messages/BidNotificationMessage.cs index da733f3..34d05f1 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Hubs/Messages/BidNotificationMessage.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Hubs/Messages/BidNotificationMessage.cs @@ -6,6 +6,11 @@ using System.Threading.Tasks; namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages { + + /// + /// this message sends update to the clients. so it sends current (the already winner) price, + /// sends the ACTUAL bidstep, so the new price, and next bid can be calculated on the client side + /// public class BidNotificationMessage { public string ProductName { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs index 99b9c5f..47e68e2 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs @@ -9,6 +9,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models { public record ProductBidBoxViewModel: BaseNopModel { + public int ProductToAuctionId { get; set; } public int AuctionId { get; set; } public int ProductId { get; set; } public int CustomerId { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index 76f3128..da4ca46 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -2,7 +2,11 @@ @inject IJsonHelper JsonHelper; @* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@ -
+ + +
@@ -11,78 +15,70 @@ @String.Format("{0:c}", Model.BasePrice) @* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@ -
-
- Current Price: - - @String.Format("{0:c}", Model.CurrentPrice) - @* @(decimal?.Round(Model.CurrentPrice, 2, MidpointRounding.AwayFromZero)) *@ - -
+
Bid Step: @String.Format("{0:c}", Model.LicitStep)
- + @* *@
- + - + *@
\ No newline at end of file