Implement Tare; Implement OrderItemPallet;, improvements, fixes, etc...

This commit is contained in:
Loretta 2025-10-10 08:00:06 +02:00
parent c179a75ba2
commit 2b6e022f8b
8 changed files with 237 additions and 116 deletions

View File

@ -15,6 +15,7 @@ using Mango.Nop.Core.Models;
using Nop.Core; using Nop.Core;
using Nop.Core.Domain.Customers; using Nop.Core.Domain.Customers;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.FruitBankPlugin.Factories;
using Nop.Services.Customers; using Nop.Services.Customers;
using Nop.Services.Localization; using Nop.Services.Localization;
using Nop.Web.Framework.Controllers; using Nop.Web.Framework.Controllers;
@ -154,7 +155,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
_logger.Detail($"AddShippingItemPallet invoked; {shippingItemPallet}"); _logger.Detail($"AddShippingItemPallet invoked; {shippingItemPallet}");
return await ctx.AddShippingItemPalletAsync(shippingItemPallet); if (!await ctx.AddShippingItemPalletSafeAsync(shippingItemPallet)) return null;
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
} }
[SignalR(SignalRTags.UpdateShippingItemPallet)] [SignalR(SignalRTags.UpdateShippingItemPallet)]
@ -164,25 +166,39 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
_logger.Detail($"UpdateShippingItemPallet invoked; {shippingItemPallet}"); _logger.Detail($"UpdateShippingItemPallet invoked; {shippingItemPallet}");
return await ctx.UpdateShippingItemPalletAsync(shippingItemPallet); if (!await ctx.UpdateShippingItemPalletSafeAsync(shippingItemPallet)) return null;
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
} }
[SignalR(SignalRTags.AddOrUpdateMeasuredShippingItemPallets)] [SignalR(SignalRTags.AddOrUpdateMeasuredShippingItemPallets)]
public async Task<ShippingItem> AddOrUpdateMeasuredShippingItemPallets(List<ShippingItemPallet> shippingItemPallets) public async Task<ShippingItem> AddOrUpdateMeasuredShippingItemPallets(List<ShippingItemPallet> shippingItemPallets)
{ {
ArgumentNullException.ThrowIfNull(shippingItemPallets); // ArgumentNullException.ThrowIfNull(shippingItemPallets);
_logger.Detail($"AddOrUpdateMeasuredShippingItemPallets invoked; count: {shippingItemPallets.Count}"); // _logger.Detail($"AddOrUpdateMeasuredShippingItemPallets invoked; count: {shippingItemPallets.Count}");
if (shippingItemPallets.Count == 0) return null; // if (shippingItemPallets.Count == 0) return null;
var shippingItemId = shippingItemPallets.FirstOrDefault()!.ShippingItemId; // var shippingItemId = shippingItemPallets.FirstOrDefault()!.ShippingItemId;
if (shippingItemId <= 0 || shippingItemPallets.Any(x => x.ShippingItemId != shippingItemId)) return null; // if (shippingItemId <= 0 || shippingItemPallets.Any(x => x.ShippingItemId != shippingItemId)) return null;
var shippingItem = await ctx.ShippingItems.GetByIdAsync(shippingItemId, false); // var shippingItem = await ctx.ShippingItems.GetByIdAsync(shippingItemId, false);
shippingItem.ShippingItemPallets = shippingItemPallets.Where(sip => sip.IsValidMeasuringValues(shippingItem.IsMeasurable)).ToList(); // shippingItem.ShippingItemPallets = shippingItemPallets.Where(sip => sip.IsValidMeasuringValues(shippingItem.IsMeasurable)).ToList();
return await UpdateMeasuredShippingItem(shippingItem); // return await UpdateMeasuredShippingItem(shippingItem);
return null;
}
[SignalR(SignalRTags.AddOrUpdateMeasuredShippingItemPallet)]
public async Task<ShippingItemPallet> AddOrUpdateMeasuredShippingItemPallet(ShippingItemPallet shippingItemPallet)
{
ArgumentNullException.ThrowIfNull(shippingItemPallet);
_logger.Detail($"AddOrUpdateMeasuredShippingItemPallet invoked; {shippingItemPallet}");
if (!await ctx.AddOrUpdateShippingItemPalletSafeAsync(shippingItemPallet)) return null;
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
} }
[SignalR(SignalRTags.GetShippingDocuments)] [SignalR(SignalRTags.GetShippingDocuments)]

View File

@ -32,6 +32,7 @@ public class FruitBankDbContext : MgDbContextBase,
IShippingDocumentDbSet<ShippingDocumentDbTable>, IShippingDocumentDbSet<ShippingDocumentDbTable>,
IShippingItemDbSet<ShippingItemDbTable>, IShippingItemDbSet<ShippingItemDbTable>,
IShippingItemPalletDbSet<ShippingItemPalletDbTable>, IShippingItemPalletDbSet<ShippingItemPalletDbTable>,
IOrderItemPalletDbSet<OrderItemPalletDbTable>,
IShippingDocumentToFilesDbSet<ShippingDocumentToFilesDbTable>, IShippingDocumentToFilesDbSet<ShippingDocumentToFilesDbTable>,
IFilesDbSet<FilesDbTable> IFilesDbSet<FilesDbTable>
{ {
@ -46,6 +47,8 @@ public class FruitBankDbContext : MgDbContextBase,
public ShippingItemDbTable ShippingItems { get; set; } public ShippingItemDbTable ShippingItems { get; set; }
public ShippingItemPalletDbTable ShippingItemPallets { get; set; } public ShippingItemPalletDbTable ShippingItemPallets { get; set; }
public OrderItemPalletDbTable OrderItemPallets { get; set; }
public FilesDbTable Files { get; set; } public FilesDbTable Files { get; set; }
public ShippingDocumentToFilesDbTable ShippingDocumentToFiles { get; set; } public ShippingDocumentToFilesDbTable ShippingDocumentToFiles { get; set; }
@ -53,7 +56,7 @@ public class FruitBankDbContext : MgDbContextBase,
public IRepository<Customer> Customers { get; set; } public IRepository<Customer> Customers { get; set; }
public IRepository<CustomerRole> CustomerRoles { get; set; } public IRepository<CustomerRole> CustomerRoles { get; set; }
public IRepository<CustomerCustomerRoleMapping> CustomerRoleMappings { get; set; } public IRepository<CustomerCustomerRoleMapping> CustomerRoleMappings { get; set; }
public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable, ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable,
@ -150,15 +153,6 @@ public class FruitBankDbContext : MgDbContextBase,
}); });
} }
public async Task DeleteShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
{
await TransactionSafeAsync(async tr =>
{
await ShippingItemPallets.DeleteAsync(shippingItemPallet, false);
return true;
});
}
public Task<bool> UpdateMeasuredShippingItemSafeAsync(ShippingItem shippingItem) public Task<bool> UpdateMeasuredShippingItemSafeAsync(ShippingItem shippingItem)
{ {
if (shippingItem.IsValidMeasuringValues()) return UpdateShippingItemSafeAsync(shippingItem); if (shippingItem.IsValidMeasuringValues()) return UpdateShippingItemSafeAsync(shippingItem);
@ -168,108 +162,101 @@ public class FruitBankDbContext : MgDbContextBase,
} }
public Task<bool> UpdateShippingItemSafeAsync(ShippingItem shippingItem) public Task<bool> UpdateShippingItemSafeAsync(ShippingItem shippingItem)
=> TransactionSafeAsync(async _ => await UpdateShippingItemAsync(shippingItem));
public async Task<bool> UpdateShippingItemAsync(ShippingItem shippingItem)
{ {
if (shippingItem == null) try
{ {
Logger.Error("shippingItem == null"); Product? product = null;
return Task.FromResult(false); var productIsMeasurable = false;
}
return TransactionSafeAsync(async tr => if (shippingItem.ProductId > 0)
{
try
{ {
//Mi van ha nem jött meg a termék? Nem fogják tudni menteni... - J. product = await Products.GetByIdAsync(shippingItem.ProductId);
Product? product = null; if (product == null)
var productIsMeasurable = false; throw new Exception($"shippingItem.ProductId > 0 && product == null; shippingItem.ProductId: {shippingItem.ProductId}");
if (shippingItem.ProductId > 0) productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
{ }
product = await Products.GetByIdAsync(shippingItem.ProductId);
if (product == null) shippingItem.IsMeasurable = productIsMeasurable;
throw new Exception($"shippingItem.ProductId > 0 && product == null; shippingItem.ProductId: {shippingItem.ProductId}");
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id); //if (shippingItem.ShippingItemPallets is { Count: > 0 }) await AddOrUpdateShippingItemPalletAsync(shippingItem);
}
shippingItem.IsMeasurable = productIsMeasurable; //await AddOrUpdateShippingItemPalletAsync(shippingItem.ShippingItemPallets.Where(x => x.IsValidMeasuringValues(shippingItem.IsMeasurable)), shippingItem);
if (shippingItem.ShippingItemPallets is { Count: > 0 }) await AddOrUpdateShippingItemPalletAsync(shippingItem);
//await AddOrUpdateShippingItemPalletAsync(shippingItem.ShippingItemPallets.Where(x => x.IsValidMeasuringValues(shippingItem.IsMeasurable)), shippingItem);
//Nem tudhatjuk, h minden Pallet-et tartalmaz-e a shippingItem paraméter! A Biztonság kedvéért lekérjük db-ből! - J. //Nem tudhatjuk, h minden Pallet-et tartalmaz-e a shippingItem paraméter! A Biztonság kedvéért lekérjük db-ből! - J.
shippingItem.ShippingItemPallets = await ShippingItemPallets.GetAllByShippingItemIdAsync(shippingItem.Id, false).ToListAsync(); shippingItem.ShippingItemPallets = await ShippingItemPallets.GetAllByShippingItemIdAsync(shippingItem.Id, false).ToListAsync();
//Update előtt kivesszük a korábbi ShippingItem-et a db-ből! - J. //Update előtt kivesszük a korábbi ShippingItem-et a db-ből! - J.
var dbShippingItem = await ShippingItems.GetByIdAsync(shippingItem.Id, false); var dbShippingItem = await ShippingItems.GetByIdAsync(shippingItem.Id, false);
if (dbShippingItem == null) throw new Exception($"dbShippingItem == null; shippingItem.Id: {shippingItem.Id}"); if (dbShippingItem == null) throw new Exception($"dbShippingItem == null; shippingItem.Id: {shippingItem.Id}");
var isMeasuredPrerequisite = product != null && shippingItem.PalletsOnDocument == shippingItem.ShippingItemPallets.Count var isMeasuredPrerequisite = product != null && shippingItem.PalletsOnDocument == shippingItem.ShippingItemPallets.Count
&& shippingItem.ShippingItemPallets.All(x => x.IsMeasuredAndValid(shippingItem.IsMeasurable)); && shippingItem.ShippingItemPallets.All(x => x.IsMeasuredAndValid(shippingItem.IsMeasurable));
SetupShippingItemMeasuringValues(shippingItem, isMeasuredPrerequisite); SetupShippingItemMeasuringValues(shippingItem, isMeasuredPrerequisite);
shippingItem.IsMeasured = isMeasuredPrerequisite && shippingItem.IsValidMeasuringValues(); shippingItem.IsMeasured = isMeasuredPrerequisite && shippingItem.IsValidMeasuringValues();
await ShippingItems.UpdateAsync(shippingItem, shippingItem.IsMeasured != dbShippingItem.IsMeasured); await ShippingItems.UpdateAsync(shippingItem, shippingItem.IsMeasured != dbShippingItem.IsMeasured);
if (shippingItem.ProductId == dbShippingItem.ProductId &&
shippingItem.IsMeasured == dbShippingItem.IsMeasured && shippingItem.IsMeasurable == dbShippingItem.IsMeasurable &&
shippingItem.MeasuredQuantity == dbShippingItem.MeasuredQuantity &&
// ReSharper disable once CompareOfFloatsByEqualityOperator
shippingItem.MeasuredNetWeight == dbShippingItem.MeasuredNetWeight &&
// ReSharper disable once CompareOfFloatsByEqualityOperator
shippingItem.MeasuredGrossWeight == dbShippingItem.MeasuredGrossWeight)
{
return true;
}
var productIdChanged = shippingItem.ProductId != dbShippingItem.ProductId;
if (shippingItem.IsMeasured)
{
product!.StockQuantity += productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
if (!await UpdateProductStockQuantityAsync(product, true))
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {product.Id}");
if (productIsMeasurable)
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id,
productIdChanged ? shippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight,
productIdChanged ? shippingItem.MeasuredGrossWeight : shippingItem.MeasuredGrossWeight - dbShippingItem.MeasuredGrossWeight,
shippingItem.IsMeasurable, true);
}
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
if (!productIdChanged && (shippingItem.IsMeasured || !dbShippingItem.IsMeasured)) return true;
product = await Products.GetByIdAsync(dbShippingItem.ProductId);
if (product != null)
{
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
product.StockQuantity -= dbShippingItem.MeasuredQuantity;
if (!await UpdateProductStockQuantityAsync(product, true))
throw new Exception($"UpdateProductStockQuantity() == false; dbShippingItem! product.Id: {product.Id}");
if (!productIsMeasurable) return true;
var measuringValues = new MeasuringAttributeValues(product.Id, -dbShippingItem.MeasuredNetWeight, -dbShippingItem.MeasuredGrossWeight, dbShippingItem.IsMeasurable);
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
}
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
//else //TODO: productIdUnchanged-et lekezelni! - J.
if (shippingItem.ProductId == dbShippingItem.ProductId &&
shippingItem.IsMeasured == dbShippingItem.IsMeasured && shippingItem.IsMeasurable == dbShippingItem.IsMeasurable &&
shippingItem.MeasuredQuantity == dbShippingItem.MeasuredQuantity &&
// ReSharper disable once CompareOfFloatsByEqualityOperator
shippingItem.MeasuredNetWeight == dbShippingItem.MeasuredNetWeight &&
// ReSharper disable once CompareOfFloatsByEqualityOperator
shippingItem.MeasuredGrossWeight == dbShippingItem.MeasuredGrossWeight)
{
return true; return true;
} }
catch (Exception ex)
var productIdChanged = shippingItem.ProductId != dbShippingItem.ProductId;
if (shippingItem.IsMeasured)
{ {
throw new Exception($"UpdateShippingItemSafeAsync->TransactionSafeAsync error! shippingItem.Id: {shippingItem.Id}; ex: {ex.Message}", ex); product!.StockQuantity += productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
if (!await UpdateProductStockQuantityAsync(product, true))
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {product.Id}");
if (productIsMeasurable)
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id,
productIdChanged ? shippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight,
productIdChanged ? shippingItem.MeasuredGrossWeight : shippingItem.MeasuredGrossWeight - dbShippingItem.MeasuredGrossWeight,
shippingItem.IsMeasurable, true);
} }
});
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
if (!productIdChanged && (shippingItem.IsMeasured || !dbShippingItem.IsMeasured)) return true;
product = await Products.GetByIdAsync(dbShippingItem.ProductId);
if (product != null)
{
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
product.StockQuantity -= dbShippingItem.MeasuredQuantity;
if (!await UpdateProductStockQuantityAsync(product, true))
throw new Exception($"UpdateProductStockQuantity() == false; dbShippingItem! product.Id: {product.Id}");
if (!productIsMeasurable) return true;
var measuringValues = new MeasuringAttributeValues(product.Id, -dbShippingItem.MeasuredNetWeight, -dbShippingItem.MeasuredGrossWeight, dbShippingItem.IsMeasurable);
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
}
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
//else //TODO: productIdUnchanged-et lekezelni! - J.
return true;
}
catch (Exception ex)
{
throw new Exception($"UpdateShippingItemAsync error! {shippingItem}; ex: {ex.Message}", ex);
}
} }
private static void SetupShippingItemMeasuringValues(ShippingItem shippingItem, bool shippingItemIsMeasured) private static void SetupShippingItemMeasuringValues(ShippingItem shippingItem, bool shippingItemIsMeasured)
@ -342,8 +329,8 @@ public class FruitBankDbContext : MgDbContextBase,
}); });
} }
public Task AddOrUpdateShippingItemPalletSafeAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletSafeAsync(shippingItem.ShippingItemPallets!, shippingItem); public Task AddOrUpdateShippingItemPalletsSafeAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletsSafeAsync(shippingItem.ShippingItemPallets!, shippingItem);
public Task<bool> AddOrUpdateShippingItemPalletSafeAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem) public Task<bool> AddOrUpdateShippingItemPalletsSafeAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem)
{ {
return TransactionSafeAsync(async tr => return TransactionSafeAsync(async tr =>
{ {
@ -354,7 +341,7 @@ public class FruitBankDbContext : MgDbContextBase,
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new Exception($"AddOrUpdateShippingItemPalletSafeAsync->TransactionSafeAsync error! ex: {ex.Message}", ex); throw new Exception($"AddOrUpdateShippingItemPalletsSafeAsync->TransactionSafeAsync error! ex: {ex.Message}", ex);
} }
}); });
} }
@ -370,6 +357,8 @@ public class FruitBankDbContext : MgDbContextBase,
throw new Exception($"AddOrUpdateShippingItemPalletAsync->AddOrUpdateShippingItemPalletAsync() == null"); throw new Exception($"AddOrUpdateShippingItemPalletAsync->AddOrUpdateShippingItemPalletAsync() == null");
} }
} }
public async Task<bool> AddOrUpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
=> await TransactionSafeAsync(async tr => await AddOrUpdateShippingItemPalletAsync(shippingItemPallet) != null);
public async Task<ShippingItemPallet?> AddOrUpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet) public async Task<ShippingItemPallet?> AddOrUpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet)
{ {
@ -378,6 +367,15 @@ public class FruitBankDbContext : MgDbContextBase,
return await UpdateShippingItemPalletAsync(shippingItemPallet); return await UpdateShippingItemPalletAsync(shippingItemPallet);
} }
public async Task DeleteShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
{
await TransactionSafeAsync(async tr =>
{
await ShippingItemPallets.DeleteAsync(shippingItemPallet, false);
return true;
});
}
private async Task<bool> SetupShippingItemPalletMeauringValues(ShippingItemPallet shippingItemPallet) private async Task<bool> SetupShippingItemPalletMeauringValues(ShippingItemPallet shippingItemPallet)
{ {
var shippingItem = shippingItemPallet.ShippingItem ?? await ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false); var shippingItem = shippingItemPallet.ShippingItem ?? await ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false);
@ -385,6 +383,7 @@ public class FruitBankDbContext : MgDbContextBase,
if (!shippingItem.IsMeasurable) if (!shippingItem.IsMeasurable)
{ {
shippingItemPallet.TareWeight = 0;
shippingItemPallet.PalletWeight = 0; shippingItemPallet.PalletWeight = 0;
shippingItemPallet.GrossWeight = 0; shippingItemPallet.GrossWeight = 0;
} }

View File

@ -0,0 +1,10 @@
using FruitBank.Common.Entities;
using Mango.Nop.Core.Interfaces;
using Nop.Data;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
public interface IOrderItemPalletDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<OrderItemPallet>
{
public TDbTable OrderItemPallets { get; set; }
}

View File

@ -0,0 +1,21 @@
using FruitBank.Common.Interfaces;
using Mango.Nop.Core.Entities;
using Mango.Nop.Core.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Events;
using Nop.Data;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class MeasuringItemPalletBaseDbTable<TEntity>(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger) : MgDbTableBase<TEntity>(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger) where TEntity
: MgEntityBase, IMeasuringItemPalletBase
{
protected virtual void BeforeInsertOrUpdate(IMeasuringItemPalletBase measuringItemPalletBase)
{
if (measuringItemPalletBase.IsValidSafeMeasuringValues()) return;
throw new Exception($"MeasuringItemPalletBaseDbTable->BeforeInsertOrUpdate(); Invalid measuring value(s); {measuringItemPalletBase}");
}
}

View File

@ -0,0 +1,44 @@
using FruitBank.Common.Entities;
using LinqToDB;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Events;
using Nop.Data;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class OrderItemPalletDbTable : MeasuringItemPalletBaseDbTable<OrderItemPallet>
{
public OrderItemPalletDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}
protected override void OnUpdate(OrderItemPallet entity)
{
BeforeInsertOrUpdate(entity);
base.OnUpdate(entity);
}
protected override void OnInsert(OrderItemPallet entity)
{
BeforeInsertOrUpdate(entity);
base.OnInsert(entity);
}
public override IQueryable<OrderItemPallet> GetAll() => base.GetAll();
public IQueryable<OrderItemPallet> GetAll(bool loadRelations)
{
return loadRelations
? GetAll().LoadWith(oip => oip.OrderItem)
: GetAll();
}
public Task<OrderItemPallet> GetByIdAsync(int id, bool loadRelations)
=> GetAll(loadRelations).FirstOrDefaultAsync(oip => oip.Id == id);
public IQueryable<OrderItemPallet> GetAllByOrderItemIdAsync(int orderItemId, bool loadRelations)
=> GetAll(loadRelations).Where(oip => oip.OrderItemId == orderItemId);
}

View File

@ -9,7 +9,7 @@ using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class ShippingItemPalletDbTable : MgDbTableBase<ShippingItemPallet> public class ShippingItemPalletDbTable : MeasuringItemPalletBaseDbTable<ShippingItemPallet>
{ {
public ShippingItemPalletDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger) public ShippingItemPalletDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger) : base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
@ -47,11 +47,4 @@ public class ShippingItemPalletDbTable : MgDbTableBase<ShippingItemPallet>
public IQueryable<ShippingItemPallet> GetAllByShippingItemIdAsync(int shippingItemId, bool loadRelations) public IQueryable<ShippingItemPallet> GetAllByShippingItemIdAsync(int shippingItemId, bool loadRelations)
=> GetAll(loadRelations).Where(sip => sip.ShippingItemId == shippingItemId); => GetAll(loadRelations).Where(sip => sip.ShippingItemId == shippingItemId);
private static void BeforeInsertOrUpdate(ShippingItemPallet shippingItemPallet)
{
if (shippingItemPallet.IsValidSafeMeasuringValues()) return;
throw new Exception($"ShippingItemPalletDbTable->BeforeInsertOrUpdate(); Invalid measuring value(s); shippingItemPallet: {shippingItemPallet}");
}
} }

View File

@ -19,7 +19,17 @@ 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) :
MgEventConsumer(httpContextAccessor, logWriters), IConsumer<EntityUpdatedEvent<ShippingItem>>, IConsumer<EntityUpdatedEvent<ShippingDocument>> MgEventConsumer(httpContextAccessor, logWriters),
IConsumer<EntityDeletedEvent<Shipping>>,
IConsumer<EntityInsertedEvent<ShippingItem>>,
IConsumer<EntityUpdatedEvent<ShippingItem>>,
IConsumer<EntityDeletedEvent<ShippingItem>>,
IConsumer<EntityInsertedEvent<ShippingDocument>>,
IConsumer<EntityUpdatedEvent<ShippingDocument>>,
IConsumer<EntityDeletedEvent<ShippingDocument>>,
IConsumer<EntityInsertedEvent<ShippingItemPallet>>,
IConsumer<EntityUpdatedEvent<ShippingItemPallet>>,
IConsumer<EntityDeletedEvent<ShippingItemPallet>>
{ {
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage) public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
{ {
@ -37,9 +47,36 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
await base.HandleEventAsync(eventMessage); await base.HandleEventAsync(eventMessage);
} }
public async Task HandleEventAsync(EntityInsertedEvent<ShippingItemPallet> eventMessage)
{
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity);
}
public async Task HandleEventAsync(EntityUpdatedEvent<ShippingItemPallet> eventMessage)
{
Logger.Info($"HandleEventAsync EntityUpdatedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity);
}
public async Task HandleEventAsync(EntityDeletedEvent<ShippingItemPallet> eventMessage)
{
Logger.Info($"HandleEventAsync EntityDeletedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity);
}
private async Task UpdateShippingItemMeasuringValuesAsync(ShippingItemPallet shippingItemPallet)
{
var shippingItem = await ctx.ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false);
await ctx.UpdateShippingItemAsync(shippingItem);
}
public async Task HandleEventAsync(EntityInsertedEvent<ShippingItem> eventMessage) public async Task HandleEventAsync(EntityInsertedEvent<ShippingItem> eventMessage)
{ {
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItem>; id: {eventMessage.Entity.Id}"); Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
await UpdateShippingDocumentIsAllMeasuredAsync(eventMessage.Entity); await UpdateShippingDocumentIsAllMeasuredAsync(eventMessage.Entity);
} }

View File

@ -18,6 +18,7 @@ public partial class NameCompatibility : INameCompatibility
{ typeof(ShippingDocument), FruitBankConstClient.ShippingDocumentDbTableName }, { typeof(ShippingDocument), FruitBankConstClient.ShippingDocumentDbTableName },
{ typeof(ShippingItem), FruitBankConstClient.ShippingItemDbTableName}, { typeof(ShippingItem), FruitBankConstClient.ShippingItemDbTableName},
{ typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName}, { typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName},
{ typeof(OrderItemPallet), FruitBankConstClient.OrderItemPalletDbTableName},
{ typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName}, { typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName},
}; };