From 16dbfb18e23ec407661b2b120b9783f632eb524f Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Oct 2025 11:23:08 +0200 Subject: [PATCH] small fixes --- .../Controllers/InnVoiceOrderController.cs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/InnVoiceOrderController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/InnVoiceOrderController.cs index fd3152d..d20e6aa 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/InnVoiceOrderController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/InnVoiceOrderController.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Nop.Core; using Nop.Core.Domain.Orders; +using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; using Nop.Plugin.Misc.FruitBankPlugin.Services; using Nop.Services.Catalog; using Nop.Services.Common; @@ -29,6 +31,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers private readonly IProductService _productService; private readonly InnVoiceOrderService _innVoiceOrderService; private readonly IGenericAttributeService _genericAttributeService; + private readonly FruitBankDbContext _dbContext; public InnVoiceOrderController( IOrderService orderService, @@ -38,7 +41,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers ICountryService countryService, IProductService productService, InnVoiceOrderService innVoiceOrderService, - IGenericAttributeService genericAttributeService) + IGenericAttributeService genericAttributeService, + FruitBankDbContext dbContext) { _orderService = orderService; _workContext = workContext; @@ -48,6 +52,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers _productService = productService; _innVoiceOrderService = innVoiceOrderService; _genericAttributeService = genericAttributeService; + _dbContext = dbContext; } /// @@ -75,10 +80,16 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers // Get shipping address var shippingAddress = await _customerService.GetCustomerShippingAddressAsync(customer); + + if (shippingAddress == null) + { + shippingAddress = billingAddress; + } + var shippingCountry = shippingAddress != null ? await _countryService.GetCountryByAddressAsync(shippingAddress) : null; - var shippingCountryCode = shippingCountry?.TwoLetterIsoCode ?? billingCountryCode; + var shippingCountryCode = shippingCountry?.TwoLetterIsoCode ?? billingCountryCode; // Create order request var orderRequest = new OrderCreateRequest @@ -92,8 +103,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers MegrendelestombID = 1, // Configure this based on your setup MegrendelesKelte = order.CreatedOnUtc.ToLocalTime(), Hatarido = DateTime.Now.AddDays(7), // 7 days delivery time - Devizanem = order.CustomerCurrencyCode, - FizetesiMod = order.PaymentMethodSystemName, + Devizanem = "HUF", //TODO get real deault - A. + FizetesiMod = order.PaymentMethodSystemName ?? "átutalás", Email = billingAddress.Email, Telefon = billingAddress.PhoneNumber, MegrendelesSzamStr = order.Id.ToString() @@ -113,8 +124,10 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers var orderItems = await _orderService.GetOrderItemsAsync(order.Id); foreach (var item in orderItems) { - var product = await _productService.GetProductByIdAsync(item.ProductId); - + //var productDTO = await _productService.GetProductByIdAsync(item.ProductId); + var product = _dbContext.ProductDtos.GetById(item.ProductId); + //string unit = product != null && product.IsMeasurable ? "kg" : "kt"; + orderRequest.AddItem(new InnVoiceOrderItem { TetelNev = product?.Name ?? "Product", @@ -122,8 +135,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers Brutto = true, EgysegAr = item.UnitPriceInclTax, Mennyiseg = item.Quantity, - MennyisegEgyseg = "db", - CikkSzam = product?.Sku + MennyisegEgyseg = "kt", + CikkSzam = "" }); }