Compare commits

..

No commits in common. "760e30847c9a8287dfd3540493e26ff74cada87a" and "992e4a6c40a04654cb94edf31395f1e70f123d59" have entirely different histories.

5 changed files with 83 additions and 110 deletions

View File

@ -127,12 +127,9 @@ public class AuctionPublicViewComponent : NopViewComponent
auctionId = valami.Id; auctionId = valami.Id;
} }
var productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id);
productBidBoxViewModel.WidgetZone = widgetZone; productBidBoxViewModel.WidgetZone = widgetZone;
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue; productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue; productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id;
productBidBoxViewModel.AuctionId = auctionId; productBidBoxViewModel.AuctionId = auctionId;
productBidBoxViewModel.CustomerId = customer.Id; productBidBoxViewModel.CustomerId = customer.Id;
productBidBoxViewModel.ProductId = productDetailsModel.Id; productBidBoxViewModel.ProductId = productDetailsModel.Id;

View File

@ -39,16 +39,9 @@
"hideMethod": "fadeOut" "hideMethod": "fadeOut"
}); });
$('.toast-success').css("background-color", "#4caf50"); $('.toast-success').css("background-color", "#4caf50");
const publicProductBidBox = document.getElementById("publicProductBidBox");
if (publicProductBidBox) {
refreshPublicBidBox(data);
}
}, },
auctionUpdateAlternate: function (data) { auctionUpdateAlternate: function (data) {
const widgetPriceElement = document.getElementById("WidgetPrice"); const widgetPriceElement = document.getElementById("WidgetPrice");
if (widgetPriceElement) { if (widgetPriceElement) {
widgetPriceElement.textContent = data.bidPrice; // Update the price widgetPriceElement.textContent = data.bidPrice; // Update the price
console.log(`WidgetPrice updated to: ${data.bidPrice}`); console.log(`WidgetPrice updated to: ${data.bidPrice}`);
@ -56,25 +49,20 @@
console.warn("Element with ID 'WidgetPrice' not found in the DOM."); console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
} }
}, },
//auctionUpdate: function (data) { auctionUpdate: function (data) {
// // Refresh the ViewComponent using AJAX // Refresh the ViewComponent using AJAX
// $.ajax({ $.ajax({
// url: '/Auction/RefreshAuctionWidget', // Controller endpoint url: '/Auction/RefreshAuctionWidget', // Controller endpoint
// type: 'POST', method: 'GET',
// contentType: 'application/json', success: function (response) {
// data: JSON.stringify({ //$('#auction-widget').html(response); // Update the DOM element
// WidgetZone: data.WidgetZone, console.log("Auction widget refreshed!");
// ProductId: data.ProductId },
// }), error: function (error) {
// success: function (response) { console.error("Error refreshing auction widget:", error);
// //$('#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 // Add more handlers as needed
default: function (data) { default: function (data) {

View File

@ -6,11 +6,6 @@ using System.Threading.Tasks;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
{ {
/// <summary>
/// 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
/// </summary>
public class BidNotificationMessage public class BidNotificationMessage
{ {
public string ProductName { get; set; } public string ProductName { get; set; }

View File

@ -9,7 +9,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
{ {
public record ProductBidBoxViewModel: BaseNopModel public record ProductBidBoxViewModel: BaseNopModel
{ {
public int ProductToAuctionId { get; set; }
public int AuctionId { get; set; } public int AuctionId { get; set; }
public int ProductId { get; set; } public int ProductId { get; set; }
public int CustomerId { get; set; } public int CustomerId { get; set; }

View File

@ -2,11 +2,7 @@
@inject IJsonHelper JsonHelper; @inject IJsonHelper JsonHelper;
@* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@ @* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@
<div class="bg-dark p-3">
<style>
</style>
<div id="publicProductBidBox" class="bg-dark p-3">
<div class="d-flex justify-content-between mb-3"> <div class="d-flex justify-content-between mb-3">
<div> <div>
@ -16,69 +12,77 @@
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@ @* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
</span> </span>
</div> </div>
<div>
<strong>Current Price:</strong>
<span class="value">
@String.Format("{0:c}", Model.CurrentPrice)
@* @(decimal?.Round(Model.CurrentPrice, 2, MidpointRounding.AwayFromZero)) *@
</span>
</div>
<div> <div>
<strong>Bid Step:</strong> <strong>Bid Step:</strong>
<span class="value">@String.Format("{0:c}", Model.LicitStep)</span> <span class="value">@String.Format("{0:c}", Model.LicitStep)</span>
</div> </div>
<div> <div>
<button id="signalRBidButton" class="btn btn-success"> <button id="bidButton" class="btn btn-success">
@* Bid @(decimal?.Round(@Model.BidPrice, 2, MidpointRounding.AwayFromZero)) *@
Bid @String.Format("{0:c}", Model.BidPrice) Bid @String.Format("{0:c}", Model.BidPrice)
</button> </button>
@* <button id="bidButton" class="btn btn-success">
Bid @String.Format("{0:c}", Model.BidPrice)
</button> *@
</div> </div>
</div> </div>
<button id="signalRBidButton" class="btn btn-success">
SignalRBidButton
</button>
<button id="testButton" class="btn btn-success">
@* <button id="testButton" class="btn btn-success">
TestButton TestButton
</button> *@ </button>
<div id="bidFeedback" class="mt-3"></div> <div id="bidFeedback" class="mt-3"></div>
</div> </div>
<script> <script>
var pageViewModel = undefined;
$(document).ready(function () { $(document).ready(function () {
pageViewModel = @Html.Raw(Json.Serialize(Model));
var pageViewModel = @Html.Raw(Json.Serialize(Model));
console.log(pageViewModel); console.log(pageViewModel);
console.log(pageViewModel.WidgetZone); console.log(pageViewModel.WidgetZone);
console.log(typeof sendMessageToServer); console.log(typeof sendMessageToServer);
// $('#bidButton').click(function () { $('#bidButton').click(function () {
// const bidPrice = $('#bidPrice').val(); const bidPrice = $('#bidPrice').val();
// // Validate bid price // Validate bid price
// if (!bidPrice || parseInt(bidPrice) < @Model.CurrentPrice + @Model.LicitStep) { if (!bidPrice || parseInt(bidPrice) < @Model.CurrentPrice + @Model.LicitStep) {
// $('#bidFeedback').text('Bid price must be at least the current price plus the licit step.') $('#bidFeedback').text('Bid price must be at least the current price plus the licit step.')
// .addClass('text-danger'); .addClass('text-danger');
// return; return;
// } }
// // AJAX POST to send the bid // AJAX POST to send the bid
// $.ajax({ $.ajax({
// url: '/Auction/PlaceBid', // Ensure this endpoint exists in your controller url: '/Auction/PlaceBid', // Ensure this endpoint exists in your controller
// type: 'POST', type: 'POST',
// contentType: 'application/json', contentType: 'application/json',
// data: JSON.stringify({ data: JSON.stringify({
// auctionId: pageViewModel.AuctionId, auctionId: pageViewModel.AuctionId,
// bidPrice: bidPrice, bidPrice: bidPrice,
// customerId: dataObject.CustomerId, customerId: dataObject.CustomerId,
// productId: dataObject.ProductId productId: dataObject.ProductId
// }), }),
// success: function (response) { success: function (response) {
// $('#bidFeedback').text(response.message).removeClass('text-danger').addClass('text-success'); $('#bidFeedback').text(response.message).removeClass('text-danger').addClass('text-success');
// }, },
// error: function (xhr) { error: function (xhr) {
// $('#bidFeedback').text('Failed to place bid: ' + xhr.responseText) $('#bidFeedback').text('Failed to place bid: ' + xhr.responseText)
// .addClass('text-danger'); .addClass('text-danger');
// } }
// }); });
// }); });
$("#signalRBidButton").on("click", function () { $("#signalRBidButton").on("click", function () {
var bidMessage = { var bidMessage = {
@ -89,42 +93,32 @@
}; };
sendMessageToServer("BidRequestMessage", bidMessage); sendMessageToServer("BidRequestMessage", bidMessage);
}); });
$('#testButton').click(function () {
$.ajax({
url: '/Auction/RefreshAuctionWidget', // Controller endpoint
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
WidgetZone: pageViewModel.WidgetZone,
ProductId: pageViewModel.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);
}
});
});
}); });
function refreshPublicBidBox(data) {
// $.ajax({
// url: '/Auction/RefreshAuctionWidget', // Controller endpoint
// type: 'POST',
// contentType: 'application/json',
// data: JSON.stringify({
// WidgetZone: pageViewModel.WidgetZone,
// ProductId: pageViewModel.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);
// }
// });
const widgetPriceElement = document.getElementById("price-value-"+pageViewModel.ProductId);
const budButtonelement = document.getElementById("signalRBidButton");
if (widgetPriceElement) {
widgetPriceElement.textContent = data.bidPrice; // Update the price
budButtonElement.textContent = data.bidPrice + data.nextStep;
console.log(`WidgetPrice updated to: ${data.bidPrice}`);
} else {
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
}
}
</script> </script>