fix
This commit is contained in:
parent
caa2a86519
commit
13a1eb204c
|
|
@ -18,7 +18,7 @@ using Nop.Services.Events;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.EventConsumers;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.EventConsumers;
|
||||||
|
|
||||||
public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, FruitBankDbContext ctx, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, IEnumerable<IAcLogWriterBase> logWriters) :
|
public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, FruitBankDbContext ctx, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, IEnumerable<IAcLogWriterBase> logWriters, IGenericAttributeService genericAttributeService) :
|
||||||
MgEventConsumer(httpContextAccessor, logWriters),
|
MgEventConsumer(httpContextAccessor, logWriters),
|
||||||
IConsumer<EntityDeletedEvent<Shipping>>,
|
IConsumer<EntityDeletedEvent<Shipping>>,
|
||||||
IConsumer<EntityInsertedEvent<ShippingItem>>,
|
IConsumer<EntityInsertedEvent<ShippingItem>>,
|
||||||
|
|
@ -34,6 +34,9 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
|
||||||
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
|
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
|
||||||
{
|
{
|
||||||
var product = eventMessage.Entity;
|
var product = eventMessage.Entity;
|
||||||
|
|
||||||
|
await SaveCustomAttributesAsync(eventMessage.Entity);
|
||||||
|
|
||||||
var isMeasurableProduct = await fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
var isMeasurableProduct = await fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||||
|
|
||||||
var shippingItems = await ctx.ShippingItems.Table
|
var shippingItems = await ctx.ShippingItems.Table
|
||||||
|
|
@ -47,6 +50,53 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
|
||||||
await base.HandleEventAsync(eventMessage);
|
await base.HandleEventAsync(eventMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task HandleEventAsync(EntityInsertedEvent<Product> eventMessage)
|
||||||
|
{
|
||||||
|
await SaveCustomAttributesAsync(eventMessage.Entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveCustomAttributesAsync(Product product)
|
||||||
|
{
|
||||||
|
if (product == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var form = httpContextAccessor.HttpContext?.Request?.Form;
|
||||||
|
if (form == null || !form.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var isMeasurable = form["IsMeasurable"].ToString().Contains("true");
|
||||||
|
|
||||||
|
// Save IsMeasurable
|
||||||
|
if (form.ContainsKey("IsMeasurable"))
|
||||||
|
{
|
||||||
|
await genericAttributeService.SaveAttributeAsync(product, "IsMeasurable", isMeasurable);
|
||||||
|
//Akkor ez kell? - Á.
|
||||||
|
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, 0, 0, isMeasurable, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save NetWeight
|
||||||
|
if (form.ContainsKey("NetWeight"))
|
||||||
|
{
|
||||||
|
var netWeightStr = form["NetWeight"].ToString();
|
||||||
|
if (!string.IsNullOrWhiteSpace(netWeightStr) && decimal.TryParse(netWeightStr, out var netWeight))
|
||||||
|
{
|
||||||
|
await genericAttributeService.SaveAttributeAsync(product, "NetWeight", netWeight);
|
||||||
|
//Akkor ez kell? - Á.
|
||||||
|
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, 0, 0, , false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save IncomingQuantity
|
||||||
|
if (form.ContainsKey("IncomingQuantity"))
|
||||||
|
{
|
||||||
|
var incomingQtyStr = form["IncomingQuantity"].ToString();
|
||||||
|
if (!string.IsNullOrWhiteSpace(incomingQtyStr) && int.TryParse(incomingQtyStr, out var incomingQuantity))
|
||||||
|
{
|
||||||
|
await genericAttributeService.SaveAttributeAsync(product, "IncomingQuantity", incomingQuantity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task HandleEventAsync(EntityInsertedEvent<ShippingItemPallet> eventMessage)
|
public async Task HandleEventAsync(EntityInsertedEvent<ShippingItemPallet> eventMessage)
|
||||||
{
|
{
|
||||||
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
|
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue