small fixes

This commit is contained in:
Adam 2025-10-23 11:23:08 +02:00
parent 236e2c6a03
commit 16dbfb18e2
1 changed files with 21 additions and 8 deletions

View File

@ -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;
}
/// <summary>
@ -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 = ""
});
}