From 76f0994d9fcb698632083bc63c1f97a0344fce54 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 11 Oct 2025 11:05:02 +0200 Subject: [PATCH] =?UTF-8?q?T=C3=A1ra,=20error=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ManagementPageController.cs | 6 ++-- .../ProductAttributesViewComponent.cs | 7 +++-- .../EventConsumers/FruitBankEventConsumer.cs | 28 +++++++++++++------ .../Models/ProductAttributesModel.cs | 13 +++++++-- .../Views/ProductAttributes.cshtml | 10 +++++++ 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs index 86a7c7c..f135f18 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs @@ -216,9 +216,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers } string analysisPrompt = "Extract the document identification number from this document, determine the type of the " + - "document from the available list, and return them as JSON: documentNumber, documentType. " + - $"Available filetypes: {nameof(DocumentType.Invoice)}, {nameof(DocumentType.ShippingDocument)} , {nameof(DocumentType.OrderConfirmation)}, {nameof(DocumentType.Unknown)}" + - "If you can't find information of any of these, return null value for that field."; + "document from the available list, and return them as JSON: documentNumber, documentType. " + + $"Available filetypes: {nameof(DocumentType.Invoice)}, {nameof(DocumentType.ShippingDocument)} , {nameof(DocumentType.OrderConfirmation)}, {nameof(DocumentType.Unknown)}" + + "If you can't find information of any of these, return null value for that field."; //here I can start preparing the file entity var metaAnalyzis = await _aiCalculationService.GetOpenAIPDFAnalysisFromText(pdfText.ToString(), analysisPrompt); diff --git a/Nop.Plugin.Misc.AIPlugin/Components/ProductAttributesViewComponent.cs b/Nop.Plugin.Misc.AIPlugin/Components/ProductAttributesViewComponent.cs index 06ba9bb..8958f9c 100644 --- a/Nop.Plugin.Misc.AIPlugin/Components/ProductAttributesViewComponent.cs +++ b/Nop.Plugin.Misc.AIPlugin/Components/ProductAttributesViewComponent.cs @@ -15,7 +15,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Components public class ProductAttributesViewComponent : NopViewComponent { private const string NET_WEIGHT_KEY = nameof(IMeasuringAttributeValues.NetWeight); - private const string GROSS_WEIGHT_KEY = nameof(IMeasuringAttributeValues.GrossWeight); + private const string TARE_KEY = nameof(ITare.Tare); private const string IS_MEASURABLE_KEY = nameof(IMeasuringAttributeValues.IsMeasurable); private readonly IGenericAttributeService _genericAttributeService; @@ -61,10 +61,13 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Components .GetAttributeAsync(dbProduct, IS_MEASURABLE_KEY, storeScope.Id); model.NetWeight = await _genericAttributeService - .GetAttributeAsync(dbProduct, NET_WEIGHT_KEY, storeScope.Id); + .GetAttributeAsync(dbProduct, NET_WEIGHT_KEY, storeScope.Id); model.IncomingQuantity = await _genericAttributeService .GetAttributeAsync(dbProduct, "IncomingQuantity", storeScope.Id); + + model.Tare = await _genericAttributeService + .GetAttributeAsync(dbProduct, TARE_KEY, storeScope.Id); } return View("~/Plugins/Misc.FruitBankPlugin/Views/ProductAttributes.cshtml", model); diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs b/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs index 1cfcb62..1829cf2 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs @@ -15,6 +15,7 @@ using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; using Nop.Plugin.Misc.FruitBankPlugin.Services; using Nop.Services.Common; using Nop.Services.Events; +using System.Globalization; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.EventConsumers; @@ -64,23 +65,24 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr if (form == null || !form.Any()) return; - var isMeasurable = form["IsMeasurable"].ToString().Contains("true"); + var store = await storeContext.GetCurrentStoreAsync(); // Save IsMeasurable - if (form.ContainsKey("IsMeasurable")) + if (form.ContainsKey(nameof(IMeasuringAttributeValues.IsMeasurable))) { - await genericAttributeService.SaveAttributeAsync(product, "IsMeasurable", isMeasurable); + var isMeasurable = form[nameof(IMeasuringAttributeValues.IsMeasurable)].ToString().Contains("true"); + await genericAttributeService.SaveAttributeAsync(product, nameof(IMeasuringAttributeValues.IsMeasurable), isMeasurable, store.Id); //Akkor ez kell? - Á. //await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync(product.Id, 0, 0, isMeasurable, false); } // Save NetWeight - if (form.ContainsKey("NetWeight")) + if (form.ContainsKey(nameof(IMeasuringAttributeValues.NetWeight))) { - var netWeightStr = form["NetWeight"].ToString(); - if (!string.IsNullOrWhiteSpace(netWeightStr) && decimal.TryParse(netWeightStr, out var netWeight)) + var netWeightStr = form[nameof(IMeasuringAttributeValues.NetWeight)].ToString(); + if (!string.IsNullOrWhiteSpace(netWeightStr) && double.TryParse(netWeightStr, NumberStyles.Float, CultureInfo.InvariantCulture, out var netWeight)) { - await genericAttributeService.SaveAttributeAsync(product, "NetWeight", netWeight); + await genericAttributeService.SaveAttributeAsync(product, nameof(IMeasuringAttributeValues.NetWeight), netWeight, store.Id); //Akkor ez kell? - Á. //await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync(product.Id, 0, 0, , false); } @@ -92,7 +94,17 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr var incomingQtyStr = form["IncomingQuantity"].ToString(); if (!string.IsNullOrWhiteSpace(incomingQtyStr) && int.TryParse(incomingQtyStr, out var incomingQuantity)) { - await genericAttributeService.SaveAttributeAsync(product, "IncomingQuantity", incomingQuantity); + await genericAttributeService.SaveAttributeAsync(product, "IncomingQuantity", incomingQuantity, store.Id); + } + } + + if (form.ContainsKey(nameof(ITare.Tare))) + { + var tareStr = form[nameof(ITare.Tare)].ToString(); + if (!string.IsNullOrWhiteSpace(tareStr) && + double.TryParse(tareStr, NumberStyles.Float, CultureInfo.InvariantCulture, out var tare)) + { + await genericAttributeService.SaveAttributeAsync(product, nameof(ITare.Tare), tare, store.Id); } } } diff --git a/Nop.Plugin.Misc.AIPlugin/Models/ProductAttributesModel.cs b/Nop.Plugin.Misc.AIPlugin/Models/ProductAttributesModel.cs index 8be1872..daca835 100644 --- a/Nop.Plugin.Misc.AIPlugin/Models/ProductAttributesModel.cs +++ b/Nop.Plugin.Misc.AIPlugin/Models/ProductAttributesModel.cs @@ -1,9 +1,10 @@ -using Nop.Web.Framework.Models; +using FruitBank.Common.Interfaces; +using Nop.Web.Framework.Models; using Nop.Web.Framework.Mvc.ModelBinding; namespace Nop.Plugin.Misc.FruitBankPlugin.Models { - public record ProductAttributesModel : BaseNopModel + public record ProductAttributesModel : BaseNopModel, IMeasurable, IMeasuringWeights, ITare { public int ProductId { get; set; } @@ -11,9 +12,15 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Models public bool IsMeasurable { get; set; } [NopResourceDisplayName("Plugins.YourCompany.ProductAttributes.Fields.NetWeight")] - public decimal? NetWeight { get; set; } + public double NetWeight { get; set; } + + [NopResourceDisplayName("Plugins.YourCompany.ProductAttributes.Fields.NetWeight")] + public double GrossWeight { get; set; } [NopResourceDisplayName("Plugins.YourCompany.ProductAttributes.Fields.IncomingQuantity")] public int? IncomingQuantity { get; set; } + + [NopResourceDisplayName("Plugins.YourCompany.ProductAttributes.Fields.Tare")] + public double Tare { get; set; } } } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AIPlugin/Views/ProductAttributes.cshtml b/Nop.Plugin.Misc.AIPlugin/Views/ProductAttributes.cshtml index e8574ed..221ea78 100644 --- a/Nop.Plugin.Misc.AIPlugin/Views/ProductAttributes.cshtml +++ b/Nop.Plugin.Misc.AIPlugin/Views/ProductAttributes.cshtml @@ -37,5 +37,15 @@ + +
+
+ +
+
+ + +
+
\ No newline at end of file