From 2de0ec7fb0f3dbc04c43bbfa1329f2c8f0c363db Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Oct 2025 10:25:08 +0200 Subject: [PATCH] merge + small fixes --- .../Controllers/CustomOrderController.cs | 61 +++++++++++++--- .../Controllers/ManagementPageController.cs | 2 +- .../Views/OrderAttributes.cshtml | 70 +++++++++++-------- .../Infrastructure/PluginNopStartup.cs | 2 +- 4 files changed, 95 insertions(+), 40 deletions(-) diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs index 481c81c..6512ddc 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs @@ -9,6 +9,7 @@ using Mango.Nop.Core.Extensions; using Mango.Nop.Core.Loggers; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using Nop.Core; using Nop.Core.Domain.Customers; using Nop.Core.Domain.Orders; using Nop.Core.Domain.Payments; @@ -49,11 +50,13 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers private readonly INotificationService _notificationService; private readonly ICustomerService _customerService; private readonly IProductService _productService; + private readonly IStoreContext _storeContext; + private readonly IWorkContext _workContext; // ... other dependencies private readonly ILogger _logger; - public CustomOrderController(FruitBankDbContext fruitBankDbContext, IOrderService orderService, IOrderModelFactory orderModelFactory, ICustomOrderSignalREndpointServer customOrderSignalREndpoint, IPermissionService permissionService, IGenericAttributeService genericAttributeService, INotificationService notificationService, ICustomerService customerService, IProductService productService, IEnumerable logWriters) + public CustomOrderController(FruitBankDbContext fruitBankDbContext, IOrderService orderService, IOrderModelFactory orderModelFactory, ICustomOrderSignalREndpointServer customOrderSignalREndpoint, IPermissionService permissionService, IGenericAttributeService genericAttributeService, INotificationService notificationService, ICustomerService customerService, IProductService productService, IEnumerable logWriters, IStoreContext storeContext, IWorkContext workContext) { _logger = new Logger(logWriters.ToArray()); @@ -66,6 +69,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers _notificationService = notificationService; _customerService = customerService; _productService = productService; + _storeContext = storeContext; + _workContext = workContext; // ... initialize other deps } @@ -152,8 +157,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers return RedirectToAction("List", "Order"); // store attributes in GenericAttribute table - await _genericAttributeService.SaveAttributeAsync(order, nameof(IMeasurable.IsMeasurable), model.IsMeasurable); - await _genericAttributeService.SaveAttributeAsync(order, nameof(IOrderDto.DateOfReceipt), model.DateOfReceipt); + await _genericAttributeService.SaveAttributeAsync(order, nameof(IMeasurable.IsMeasurable), model.IsMeasurable, _storeContext.GetCurrentStore().Id); + await _genericAttributeService.SaveAttributeAsync(order, nameof(IOrderDto.DateOfReceipt), model.DateOfReceipt, _storeContext.GetCurrentStore().Id); _notificationService.SuccessNotification("Custom attributes saved successfully."); @@ -171,6 +176,29 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers var customer = await _customerService.GetCustomerByIdAsync(customerId); if (customer == null) return RedirectToAction("List"); + var billingAddress = await _customerService.GetCustomerBillingAddressAsync(customer); + if(billingAddress == null) + { + //let's see if he has any address at all + var addresses = await _customerService.GetAddressesByCustomerIdAsync(customer.Id); + if(addresses != null && addresses.Count > 0) + { + //set the first one as billing + billingAddress = addresses[0]; + customer.BillingAddressId = billingAddress.Id; + await _customerService.UpdateCustomerAsync(customer); + } + else + { + //no address at all, cannot create order + _logger.Error($"Cannot create order for customer {customer.Id}, no billing address found."); + return RedirectToAction("List"); + } + } + + //var currency = await _workContext.GetWorkingCurrencyAsync(); + //customer.CurrencyId = currency.Id; + // Parse products var orderProducts = string.IsNullOrEmpty(orderProductsJson) ? [] : JsonConvert.DeserializeObject>(orderProductsJson); @@ -188,7 +216,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers ShippingStatus = ShippingStatus.ShippingNotRequired, CreatedOnUtc = DateTime.UtcNow, BillingAddressId = customer.BillingAddressId ?? 0, - ShippingAddressId = customer.ShippingAddressId + ShippingAddressId = customer.ShippingAddressId, + PaymentMethodSystemName = "Payments.CheckMoneyOrder", // Default payment method + CustomerCurrencyCode = "HUF", // TODO: GET Default currency - A. }; var productDtosById = await _dbContext.ProductDtos.GetAllByIds(orderProducts.Select(op => op.Id)).ToDictionaryAsync(p => p.Id, prodDto => prodDto); @@ -350,10 +380,16 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers pageIndex: 0, pageSize: maxResults); + var customersByCompanyName = await _customerService.GetAllCustomersAsync( + company: term, + pageIndex: 0, + pageSize: maxResults); + // Combine and deduplicate results var allCustomers = customersByEmail .Union(customersByFirstName) .Union(customersByLastName) + .Union(customersByCompanyName) .DistinctBy(c => c.Id) .Take(maxResults) .ToList(); @@ -362,13 +398,22 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers foreach (var customer in allCustomers) { var fullName = await _customerService.GetCustomerFullNameAsync(customer); - var displayText = !string.IsNullOrEmpty(customer.Email) - ? $"{customer.Email} ({fullName})" - : fullName; + var company = customer.Company; + + if (string.IsNullOrEmpty(fullName)) + fullName = "[No name]"; + if(string.IsNullOrEmpty(company)) + company = "[No company]"; + + string fullText = $"{company} ({fullName}), {customer.Email}"; + + //var displayText = !string.IsNullOrEmpty(customer.Email) + // ? $"{customer.Email}, {customer.Company} ({fullName})" + // : fullName; result.Add(new { - label = displayText, + label = fullText, value = customer.Id }); } diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs index a4e1e1e..2376ed1 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs @@ -381,7 +381,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers // save partner information to partners table { Id, Name, TaxId, CertificationNumber, PostalCode, Country, State, County, City, Street } if (partnerId != null) { - string partnerAnalysisPrompt = "Extract the sender information from this document, and return them as JSON: name, taxId, certificationNumber, postalCode, country, state, county, city, street. " + + string partnerAnalysisPrompt = "Extract the partner information from this document, and return them as JSON: name, taxId, certificationNumber, postalCode, country, state, county, city, street. " + "If you can't find information of any of these, return null value for that field."; //here I can start preparing the file entity diff --git a/Nop.Plugin.Misc.AIPlugin/Views/OrderAttributes.cshtml b/Nop.Plugin.Misc.AIPlugin/Views/OrderAttributes.cshtml index f8438cb..0ef286e 100644 --- a/Nop.Plugin.Misc.AIPlugin/Views/OrderAttributes.cshtml +++ b/Nop.Plugin.Misc.AIPlugin/Views/OrderAttributes.cshtml @@ -9,8 +9,6 @@
- -
Order
@@ -62,31 +60,33 @@
-
-
-
-
- + + +
+
+
+
+
+ +
+
+ +
-
- - +
+
+ +
+
+ +
-
-
-
- -
-
- - -
-
-
-
- +
+
+ +
@@ -94,9 +94,6 @@
- - - + \ No newline at end of file diff --git a/Nop.Plugin.Misc.MangoCore/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.MangoCore/Infrastructure/PluginNopStartup.cs index 9f9f140..7930106 100644 --- a/Nop.Plugin.Misc.MangoCore/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.MangoCore/Infrastructure/PluginNopStartup.cs @@ -24,7 +24,7 @@ public class PluginNopStartup : INopStartup feature.AddPolicy( "AllowBlazorClient", apiPolicy => apiPolicy - .WithOrigins("https://localhost:7144") + .WithOrigins(["https://localhost:7144", "measuringtest.fruitbank.hu", "https://localhost:60589"]) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials()