This commit is contained in:
Adam 2024-11-26 01:29:03 +01:00
parent 5a0031f9a4
commit 9f9399eb1b
4 changed files with 84 additions and 112 deletions

View File

@ -21,6 +21,7 @@ using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Catalog;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Orders;
using Nop.Web.Framework;
using Nop.Web.Framework.Mvc.Routing;
@ -68,6 +69,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure
services.AddScoped<MyProductModelFactory>();
services.AddScoped<SignalRMessageHandler>();
services.AddScoped<IOrderService, OrderService>();
services.AddScoped<IOrderProcessingService, OrderProcessingService>();
}
/// <summary>

View File

@ -2,6 +2,7 @@
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Orders;
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
@ -9,6 +10,8 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
using Nop.Services.Catalog;
using Nop.Services.Logging;
using Nop.Services.Orders;
using Nop.Services.Payments;
using Org.BouncyCastle.Crypto;
namespace Nop.Plugin.Misc.AuctionPlugin.Services;
@ -38,6 +41,7 @@ public class AuctionService : IAuctionService
private readonly IShortTermCacheManager _shortTermCacheManager;
private readonly IStaticCacheManager _staticCacheManager;
private readonly IWorkContext _workContext;
private readonly IOrderProcessingService _orderProcessingService;
private readonly ILogger _logger;
#endregion
@ -60,6 +64,7 @@ public class AuctionService : IAuctionService
IShortTermCacheManager shortTermCacheManager,
IStaticCacheManager staticCacheManager,
IWorkContext workContext,
IOrderProcessingService orderProcessingService,
ILogger logger)
{
_ctx = ctx;
@ -70,6 +75,7 @@ public class AuctionService : IAuctionService
_shortTermCacheManager = shortTermCacheManager;
_staticCacheManager = staticCacheManager;
_workContext = workContext;
_orderProcessingService = orderProcessingService;
_logger = logger;
}
@ -213,6 +219,13 @@ public class AuctionService : IAuctionService
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
public async Task CreateOrderForWinner(ProductToAuctionMapping auctionItem)
{
var processPaymentRequest = new ProcessPaymentRequest();
await _orderProcessingService.PlaceOrderAsync(processPaymentRequest);
}
#region auctions
public async Task InsertAuctionAsync(Auction auction)
{

View File

@ -58,4 +58,6 @@ public interface IAuctionService
Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly);
Task<ProductToAuctionMapping> GetProductToAuctionMappingByIdAsync(int productToAuctionMappingId);
Task UpdateProductToAuctionMappingAsync(ProductToAuctionMapping productToAuctionMapping);
Task CreateOrderForWinner(ProductToAuctionMapping productToAuctionMapping);
}

View File

@ -49,17 +49,7 @@
<h4>Manage auction!</h4>
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3">
<div>
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled" : string.Empty)>
First warning
</button>
<button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
Second warning
</button>
<button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled" : string.Empty)>
Finished
</button>
</div>
<div>
<button id="signalROpenItemButton" class="btn btn-primary" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.None || Model.AuctionStatus == AuctionStatus.Pause ? string.Empty : "disabled")>
Open item
@ -74,7 +64,17 @@
Reset auction
</button>
</div>
<div>
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled" : string.Empty)>
First warning
</button>
<button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
Second warning
</button>
<button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled" : string.Empty)>
Finished
</button>
</div>
</div>
@ -299,53 +299,6 @@
}
}
// function setButtons(auctionStatus) {
// console.log("SetButtons called" + auctionStatus);
// var bidButton = document.getElementById("signalRBidButton");
// var firstWarningButton = document.getElementById("signalRFirstWarningButton");
// var secondWarningButton = document.getElementById("signalRSecondWarningButton");
// var openItemButton = document.getElementById("signalROpenItemButton");
// var closeItemButton = document.getElementById("signalRCloseItemButton");
// var pauseItemButton = document.getElementById("signalRPauseItemButton");
// var revertBidButton = document.getElementById("signalRRevertBidButton");
// var resetItemButton = document.getElementById("signalRResetItemButton");
// switch (auctionStatus) {
// case AuctionStatus.None:
// console.log("SWITCH: 0");
// bidButton.disabled = true;
// break;
// case AuctionStatus.Active:
// console.log("SWITCH: 1");
// bidButton.disabled = false;
// firstWarningButton.disabled = false;
// break;
// case AuctionStatus.FirstWarning:
// console.log("SWITCH: 1");
// bidButton.disabled = false;
// firstWarningButton.disabled = true;
// secondWarningButton.disabled = false;
// break;
// case AuctionStatus.SecondWarning:
// // code block
// break;
// case AuctionStatus.Pause:
// // code block
// break;
// case AuctionStatus.Sold:
// // code block
// break;
// case AuctionStatus.NotSold:
// // code block
// break;
// default:
// // code block
// }
// }
function setButtons(auctionStatus) {
console.log("SetButtons called: " + auctionStatus);
@ -400,8 +353,8 @@
signalROpenItemButton: false,
signalRCloseItemButton: true,
signalRPauseItemButton: true,
signalRRevertBidButton: true,
signalRResetItemButton: true,
signalRRevertBidButton: false,
signalRResetItemButton: false,
},
[AuctionStatus.Sold]: {
signalRBidButton: true,
@ -437,6 +390,7 @@
const button = document.getElementById(buttonId);
if (button) {
button.disabled = states[buttonId];
button.hidden = states[buttonId];
} else {
console.warn(`Button with ID ${buttonId} not found.`);
}