diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs index b160af8..d873cf0 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs @@ -88,6 +88,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers protected readonly IDateTimeHelper _dateTimeHelper; protected readonly ITaxService _taxService; protected readonly MeasurementService _measurementService; + protected readonly IWorkflowMessageService _workflowMessageService; private static readonly char[] _separator = [',']; // ... other dependencies @@ -135,7 +136,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers IImportManager importManager, IDateTimeHelper dateTimeHelper, ITaxService taxService, - MeasurementService measurementService) + MeasurementService measurementService, IWorkflowMessageService workflowMessageService) { _logger = new Logger(logWriters.ToArray()); @@ -163,6 +164,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers _dateTimeHelper = dateTimeHelper; _taxService = taxService; _measurementService = measurementService; + _workflowMessageService = workflowMessageService; // ... initialize other deps } @@ -508,7 +510,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers OrderGuid = Guid.NewGuid(), CustomOrderNumber = "", CustomerId = customerId, - CustomerLanguageId = customer.LanguageId ?? 1, + CustomerLanguageId = customer.LanguageId ?? 2, CustomerTaxDisplayType = TaxDisplayType.IncludingTax, CustomerIp = string.Empty, OrderStatus = OrderStatus.Pending, @@ -519,7 +521,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers ShippingAddressId = customer.ShippingAddressId, PaymentMethodSystemName = "Payments.CheckMoneyOrder", // Default payment method CustomerCurrencyCode = "HUF", // TODO: GET Default currency - A. - + CurrencyRate = 1, OrderTotal = 0, OrderSubtotalInclTax = 0, OrderSubtotalExclTax = 0, @@ -544,7 +546,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers { //var orderDto = await _dbContext.OrderDtos.GetByIdAsync(order.Id, true); //await _sendToClient.SendMeasuringNotification("Módosult a rendelés, mérjétek újra!", orderDto); - + //var updatedOrder = await _orderService.GetOrderByIdAsync(order.Id); + await _workflowMessageService.SendOrderPlacedCustomerNotificationAsync(order, order.CustomerLanguageId); return RedirectToAction("Edit", "Order", new { id = order.Id }); } diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/InnVoiceOrderController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/InnVoiceOrderController.cs index a06a250..d8214e1 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/InnVoiceOrderController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/InnVoiceOrderController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Nop.Core; +using Nop.Core.Domain.Customers; using Nop.Core.Domain.Orders; using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; using Nop.Plugin.Misc.FruitBankPlugin.Services; @@ -15,6 +16,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using System.Xml.Linq; namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers { @@ -97,6 +99,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers return Json(new { success = false, message = "Billing address not found" }); } + //get tax info from attributes and sync with VatNumber + if(customer.VatNumber == null || customer.VatNumber == "") + { + await SynchronizeTaxInformationAsync(customer); + } + var billingCountry = await _countryService.GetCountryByAddressAsync(billingAddress); var billingCountryCode = billingCountry?.TwoLetterIsoCode ?? "HU"; @@ -107,6 +115,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers string megjegyzes = string.Empty; + + // Create order request var orderRequest = new OrderCreateRequest { @@ -476,5 +486,38 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers }); } } + + private async Task SynchronizeTaxInformationAsync(Customer customer) + { + string attributesXml = customer.CustomCustomerAttributesXML; + + string taxId = null; + + if (!string.IsNullOrWhiteSpace(attributesXml)) + { + var doc = XDocument.Parse(attributesXml); + taxId = doc.Descendants("CustomerAttribute") + .FirstOrDefault(el => (int?)el.Attribute("ID") == 1) // your TaxId attribute ID + ?.Descendants("Value") + .FirstOrDefault() + ?.Value; + } + + if (!string.IsNullOrWhiteSpace(taxId) && string.IsNullOrWhiteSpace(customer.VatNumber)) + { + customer.VatNumber = taxId; + } + else if (string.IsNullOrWhiteSpace(taxId) && !string.IsNullOrWhiteSpace(customer.VatNumber)) + { + await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync( + customer.Id, + "TaxId", + customer.VatNumber); + } + + _dbContext.Customers.Update(customer, false); + } + + } } diff --git a/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs index b69fb85..18bcd93 100644 --- a/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs @@ -29,6 +29,7 @@ using Nop.Plugin.Misc.FruitBankPlugin.Services.FileStorage; using Nop.Services.Catalog; using Nop.Services.Common; using Nop.Services.Events; +using Nop.Services.Messages; using Nop.Web.Areas.Admin.Factories; using Nop.Web.Areas.Admin.Models.Catalog; using Nop.Web.Areas.Admin.Models.Orders; @@ -118,6 +119,7 @@ public class PluginNopStartup : INopStartup //services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddSingleton(sp => new LocalFileStorageProvider() // Uses default wwwroot/uploads diff --git a/Nop.Plugin.Misc.AIPlugin/Services/EventConsumer.cs b/Nop.Plugin.Misc.AIPlugin/Services/EventConsumer.cs index 2eba046..febb2de 100644 --- a/Nop.Plugin.Misc.AIPlugin/Services/EventConsumer.cs +++ b/Nop.Plugin.Misc.AIPlugin/Services/EventConsumer.cs @@ -204,6 +204,19 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services shippingConfigurationItem.ChildNodes.Insert(4, InvoiceSyncMenuItem); + // Create a new top-level menu item + var AppDownloadMenuItem = new AdminMenuItem + { + Visible = true, + SystemName = "FruitBank", + Title = await _localizationService.GetResourceAsync("Plugins.Misc.FruitBankPlugin.Menu.AppDownload"), // You can localize this with await _localizationService.GetResourceAsync("...") + IconClass = "fas fa-mobile", + Url = _adminMenu.GetMenuItemUrl("AppDownload", "Index") + //ChildNodes = [shippingsListMenuItem, createShippingMenuItem, editShippingMenuItem] + }; + + + shippingConfigurationItem.ChildNodes.Insert(4, AppDownloadMenuItem); var invoiceListMenuItem = new AdminMenuItem {