This commit is contained in:
Loretta 2025-10-11 12:53:54 +02:00
commit c9fa03a69c
5 changed files with 50 additions and 27 deletions

View File

@ -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);

View File

@ -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<bool>(dbProduct, IS_MEASURABLE_KEY, storeScope.Id);
model.NetWeight = await _genericAttributeService
.GetAttributeAsync<decimal?>(dbProduct, NET_WEIGHT_KEY, storeScope.Id);
.GetAttributeAsync<double>(dbProduct, NET_WEIGHT_KEY, storeScope.Id);
model.IncomingQuantity = await _genericAttributeService
.GetAttributeAsync<int?>(dbProduct, "IncomingQuantity", storeScope.Id);
model.Tare = await _genericAttributeService
.GetAttributeAsync<double>(dbProduct, TARE_KEY, storeScope.Id);
}
return View("~/Plugins/Misc.FruitBankPlugin/Views/ProductAttributes.cshtml", model);

View File

@ -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;
@ -61,35 +62,29 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
return;
var form = httpContextAccessor.HttpContext?.Request?.Form;
if (form == null || form.Count == 0)
if (form == null || !form.Any())
return;
//TODO: nameof(IMeasurable) - J.
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? - Á.
//Igen, csak true kell a végére és mehet egy lépésben a NetWeight és az IsMeasurable - J.
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, netWeight, 0, isMeasurable, true);
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, 0, 0, isMeasurable, false);
}
// Save NetWeight
if (form.ContainsKey("NetWeight")) //TODO: nameof(IMeasuringNetWeight) - J.
if (form.ContainsKey(nameof(IMeasuringAttributeValues.NetWeight)))
{
var netWeightStr = form["NetWeight"].ToString();
if (!string.IsNullOrWhiteSpace(netWeightStr) && double.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? - Á.
//Igen, csak true kell a végére és mehet egy lépésben a NetWeight és az IsMeasurable - J.
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, netWeight, 0, isMeasurable, true);
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, 0, 0, , false);
}
}
@ -99,9 +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);
}
}
//await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, "IncomingQuantity", incomingQuantity);
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);
}
}
}

View File

@ -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; }
}
}

View File

@ -37,5 +37,15 @@
<span asp-validation-for="IncomingQuantity"></span>
</div>
</div>
<div class="form-group row">
<div class="col-md-3">
<nop-label asp-for="Tare" />
</div>
<div class="col-md-9">
<nop-editor asp-for="Tare" />
<span asp-validation-for="Tare"></span>
</div>
</div>
</div>
</div>