From e795abfa204fdac46e2ab07c4ea80686ebe8a38c Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 27 Nov 2024 18:49:42 +0100 Subject: [PATCH] =?UTF-8?q?order=20m=C3=BCxik?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Infrastructure/PluginNopStartup.cs | 2 ++ .../Services/AuctionService.cs | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs index 7cfb9e9..de618f9 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs @@ -71,6 +71,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); } /// diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs index 4401d9e..b4102ed 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs @@ -28,6 +28,8 @@ public class AuctionService : IAuctionService private readonly IProductService _productService; private readonly IWorkContext _workContext; private readonly IOrderProcessingService _orderProcessingService; + private readonly IShoppingCartService _shoppingCartService; + private readonly IStoreContext _storeContext; private readonly ILogger _logger; #endregion @@ -40,12 +42,21 @@ public class AuctionService : IAuctionService /// /// /// - public AuctionService(AuctionDbContext ctx, IProductService productService, IWorkContext workContext, IOrderProcessingService orderProcessingService, ILogger logger) + public AuctionService( + AuctionDbContext ctx, + IProductService productService, + IWorkContext workContext, + IOrderProcessingService orderProcessingService, + IShoppingCartService shoppingCartService, + IStoreContext storeContext, + ILogger logger) { _ctx = ctx; _productService = productService; _workContext = workContext; _orderProcessingService = orderProcessingService; + _shoppingCartService = shoppingCartService; + _storeContext = storeContext; _logger = logger; } @@ -193,12 +204,21 @@ public class AuctionService : IAuctionService { var processPaymentRequest = new ProcessPaymentRequest { + PaymentMethodSystemName = "Payments.CheckMoneyOrder", CustomerId = auctionItem.WinnerCustomerId, OrderTotal = auctionItem.CurrentPrice, OrderGuid = auctionItem.OrderGuid.IsNullOrEmpty() ? Guid.NewGuid() : auctionItem.OrderGuid.Value }; - + + var currentCustomer = await _workContext.GetCurrentCustomerAsync(); + var product = await _productService.GetProductByIdAsync(auctionItem.ProductId); + var currentStore = await _storeContext.GetCurrentStoreAsync(); processPaymentRequest.CustomValues.Add("ProductToAuctionMappingId", auctionItem.Id); + + product.DisableBuyButton = false; + + var cartResult = await _shoppingCartService.AddToCartAsync(currentCustomer, product, ShoppingCartType.ShoppingCart, currentStore.Id); + var placeOrderResult = await _orderProcessingService.PlaceOrderAsync(processPaymentRequest); if (!placeOrderResult.Success) return null;