improvements, fixes, etc...
This commit is contained in:
parent
ba52be2847
commit
0035725399
|
|
@ -4,26 +4,17 @@ using AyCode.Utils.Extensions;
|
|||
using FruitBank.Common.Entities;
|
||||
using FruitBank.Common.Interfaces;
|
||||
using FruitBank.Common.Models;
|
||||
using FruitBank.Common.Server;
|
||||
using LinqToDB;
|
||||
using LinqToDB.Common;
|
||||
using Mango.Nop.Core.Loggers;
|
||||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.ComponentModel;
|
||||
using Nop.Core.Domain.Catalog;
|
||||
using Nop.Core.Domain.Customers;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||
using Nop.Services.Catalog;
|
||||
using Nop.Services.Common;
|
||||
using System.Transactions;
|
||||
using DevExpress.XtraExport.Helpers;
|
||||
using FruitBank.Common.Dtos;
|
||||
using Mango.Nop.Core.Dtos;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Mango.Nop.Core.Extensions;
|
||||
using Nop.Core.Domain.Orders;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
|
@ -185,17 +176,17 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
{
|
||||
try
|
||||
{
|
||||
Product? product = null;
|
||||
ProductDto? productDto = null;
|
||||
var productIsMeasurable = false;
|
||||
|
||||
if (shippingItem.ProductId > 0)
|
||||
{
|
||||
product = await Products.GetByIdAsync(shippingItem.ProductId);
|
||||
productDto = await ProductDtos.GetByIdAsync(shippingItem.ProductId!.Value, true);
|
||||
|
||||
if (product == null)
|
||||
if (productDto == null)
|
||||
throw new Exception($"shippingItem.ProductId > 0 && product == null; shippingItem.ProductId: {shippingItem.ProductId}");
|
||||
|
||||
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
productIsMeasurable = productDto.IsMeasurable;
|
||||
}
|
||||
|
||||
shippingItem.IsMeasurable = productIsMeasurable;
|
||||
|
|
@ -211,7 +202,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
var dbShippingItem = await ShippingItems.GetByIdAsync(shippingItem.Id, false);
|
||||
if (dbShippingItem == null) throw new Exception($"dbShippingItem == null; shippingItem.Id: {shippingItem.Id}");
|
||||
|
||||
var isMeasuredPrerequisite = product != null && shippingItem.PalletsOnDocument == shippingItem.ShippingItemPallets.Count
|
||||
var isMeasuredPrerequisite = productDto != null && shippingItem.PalletsOnDocument == shippingItem.ShippingItemPallets.Count
|
||||
&& shippingItem.ShippingItemPallets.All(x => x.IsMeasuredAndValid(shippingItem.IsMeasurable));
|
||||
|
||||
SetupShippingItemMeasuringValues(shippingItem, isMeasuredPrerequisite);
|
||||
|
|
@ -234,36 +225,51 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
|
||||
if (shippingItem.IsMeasured)
|
||||
{
|
||||
product!.StockQuantity += productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
|
||||
var quantityInc = productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
|
||||
productDto!.StockQuantity += quantityInc;
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product, true))
|
||||
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {product.Id}");
|
||||
if (!await UpdateProductDtoStockQuantityAsync(productDto, true))
|
||||
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {productDto.Id}");
|
||||
|
||||
var incomingQuantity = productDto.GenericAttributes.GetValueOrNull<int>(nameof(IIncomingQuantity.IncomingQuantity));
|
||||
if (incomingQuantity != null)
|
||||
{
|
||||
await _fruitBankAttributeService.UpdateGenericAttributeAsync<Product, int>
|
||||
(productDto.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity.Value - quantityInc);
|
||||
}
|
||||
|
||||
if (productIsMeasurable)
|
||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id,
|
||||
{
|
||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(productDto.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)
|
||||
productDto = await ProductDtos.GetByIdAsync(dbShippingItem.ProductId);
|
||||
|
||||
if (productDto != null)
|
||||
{
|
||||
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
product.StockQuantity -= dbShippingItem.MeasuredQuantity;
|
||||
productIsMeasurable = productDto.IsMeasurable;
|
||||
productDto.StockQuantity -= dbShippingItem.MeasuredQuantity;
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product, true))
|
||||
throw new Exception($"UpdateProductStockQuantity() == false; dbShippingItem! product.Id: {product.Id}");
|
||||
if (!await UpdateProductDtoStockQuantityAsync(productDto, true))
|
||||
throw new Exception($"UpdateProductStockQuantity() == false; dbShippingItem! product.Id: {productDto.Id}");
|
||||
|
||||
var incomingQuantity = productDto.GenericAttributes.GetValueOrNull<int>(nameof(IIncomingQuantity.IncomingQuantity));
|
||||
if (incomingQuantity != null)
|
||||
{
|
||||
await _fruitBankAttributeService.UpdateGenericAttributeAsync<Product, int>
|
||||
(productDto.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity.Value + dbShippingItem.MeasuredQuantity);
|
||||
}
|
||||
|
||||
if (!productIsMeasurable) return true;
|
||||
|
||||
var measuringValues = new MeasuringAttributeValues(product.Id, -dbShippingItem.MeasuredNetWeight, -dbShippingItem.MeasuredGrossWeight, dbShippingItem.IsMeasurable);
|
||||
var measuringValues = new MeasuringAttributeValues(productDto.Id, -dbShippingItem.MeasuredNetWeight, dbShippingItem.IsMeasurable);
|
||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
|
||||
|
||||
}
|
||||
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
|
||||
//else //TODO: productIdUnchanged-et lekezelni! - J.
|
||||
|
|
@ -389,7 +395,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
(orderItemDto.Id, nameof(IMeasuringNetWeight.NetWeight), orderItemDto.NetWeight);
|
||||
|
||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>
|
||||
(orderItemDto.ProductId, -(orderItemDto.NetWeight-gaNetWeight), 0, orderItemDto.IsMeasurable, true);
|
||||
(orderItemDto.ProductId, -(orderItemDto.NetWeight-gaNetWeight), orderItemDto.IsMeasurable, true);
|
||||
}
|
||||
|
||||
return orderDto;
|
||||
|
|
@ -439,22 +445,22 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
return true;
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateProductStockQuantityAsync(int productId, bool publishEvent)
|
||||
private async Task<bool> UpdateProductDtoStockQuantityAsync(int productDtoId, bool publishEvent)
|
||||
{
|
||||
var product = await Products.GetByIdAsync(productId);
|
||||
if (product != null) return await UpdateProductStockQuantityAsync(product, publishEvent);
|
||||
var productDto = await ProductDtos.GetByIdAsync(productDtoId);
|
||||
if (productDto != null) return await UpdateProductDtoStockQuantityAsync(productDto, publishEvent);
|
||||
|
||||
Logger.Error($"product == null; id: {productId}");
|
||||
Logger.Error($"product == null; id: {productDtoId}");
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateProductStockQuantityAsync(Product product, bool publishEvent)
|
||||
private async Task<bool> UpdateProductDtoStockQuantityAsync(ProductDto productDto, bool publishEvent)
|
||||
{
|
||||
//Itt mi legyen? RollBack? - J.
|
||||
if (product.StockQuantity < 0)
|
||||
Logger.Error($"product.StockQuantity < 0; Id: {product.Id}; StockQuantity: {product.StockQuantity}");
|
||||
if (productDto.StockQuantity < 0)
|
||||
Logger.Error($"productDto.StockQuantity < 0; Id: {productDto.Id}; StockQuantity: {productDto.StockQuantity}");
|
||||
|
||||
await Products.UpdateAsync(product, publishEvent);
|
||||
await ProductDtos.UpdateAsync(productDto, publishEvent);
|
||||
return await Task.FromResult(true);
|
||||
|
||||
//var updatedRowsCount = await DataProvider.ExecuteNonQueryAsync($"update product set {nameof(Product.StockQuantity)} = {product.StockQuantity} where {nameof(Product.Id)} = {product.Id}");
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ using Nop.Services.Logging;
|
|||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
public class OrderDtoDbTable : MgDbTableBase<OrderDto>
|
||||
public class OrderDtoDbTable : MgDtoDbTableBase<OrderDto, Order>
|
||||
{
|
||||
public OrderDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
||||
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||
|
|
@ -28,9 +28,9 @@ public class OrderDtoDbTable : MgDbTableBase<OrderDto>
|
|||
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.OrderItemPallets);
|
||||
}
|
||||
|
||||
public Task<OrderDto> GetByIdAsync(int orderId) => GetAll(true).Where(x => x.Id == orderId).FirstOrDefaultAsync(null);
|
||||
public Task<OrderDto> GetByIdAsync(int orderId, bool loadRelations) => GetAll(loadRelations).Where(x => x.Id == orderId).FirstOrDefaultAsync(null);
|
||||
|
||||
public IQueryable<OrderDto> GetAllByOrderStatus(OrderStatus orderStatus) => GetAll(true).Where(o => o.OrderStatusId == (int)orderStatus);
|
||||
public IQueryable<OrderDto> GetAllByOrderStatus(OrderStatus orderStatus, bool loadRelations = true) => GetAll(loadRelations).Where(o => o.OrderStatusId == (int)orderStatus);
|
||||
|
||||
public IQueryable<OrderDto> GetAllByIds(IEnumerable<int> orderIds) => GetAll(true).Where(o => orderIds.Contains(o.Id));
|
||||
public IQueryable<OrderDto> GetAllByIds(IEnumerable<int> orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(o => orderIds.Contains(o.Id));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ using LinqToDB;
|
|||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Domain.Orders;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Services.Logging;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
public class OrderItemDtoDbTable : MgDbTableBase<OrderItemDto>
|
||||
public class OrderItemDtoDbTable : MgDtoDbTableBase<OrderItemDto, OrderItem>
|
||||
{
|
||||
public OrderItemDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
||||
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||
|
|
@ -25,7 +26,7 @@ public class OrderItemDtoDbTable : MgDbTableBase<OrderItemDto>
|
|||
.LoadWith(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes);
|
||||
}
|
||||
|
||||
public Task<OrderItemDto> GetByIdAsync(int orderItemId) => GetAll(true).Where(x => x.Id == orderItemId).FirstOrDefaultAsync(null);
|
||||
public Task<OrderItemDto> GetByIdAsync(int orderItemId, bool loadRelations) => GetAll(loadRelations).Where(x => x.Id == orderItemId).FirstOrDefaultAsync(null);
|
||||
|
||||
public IQueryable<OrderItemDto> GetAllByOrderId(int orderId)=> GetAll(true).Where(o => o.OrderId == orderId);
|
||||
public IQueryable<OrderItemDto> GetAllByOrderId(int orderId, bool loadRelations = true)=> GetAll(loadRelations).Where(o => o.OrderId == orderId);
|
||||
}
|
||||
|
|
@ -3,13 +3,14 @@ using LinqToDB;
|
|||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Domain.Catalog;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Services.Logging;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
public class ProductDtoDbTable : MgDbTableBase<ProductDto>
|
||||
public class ProductDtoDbTable : MgDtoDbTableBase<ProductDto, Product>
|
||||
{
|
||||
public ProductDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
||||
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||
|
|
@ -21,7 +22,7 @@ public class ProductDtoDbTable : MgDbTableBase<ProductDto>
|
|||
return GetAll().LoadWith(p => p.GenericAttributes);
|
||||
}
|
||||
|
||||
public Task<ProductDto> GetByIdAsync(int productId) => GetAll(true).Where(x => x.Id == productId).FirstOrDefaultAsync(null);
|
||||
public Task<ProductDto> GetByIdAsync(int productId, bool loadRelations) => GetAll(loadRelations).Where(x => x.Id == productId).FirstOrDefaultAsync(null);
|
||||
|
||||
public IQueryable<ProductDto> GetAllByIds(IEnumerable<int> productIds) => GetAll(true).Where(p => productIds.Contains(p.Id));
|
||||
public IQueryable<ProductDto> GetAllByIds(IEnumerable<int> productIds, bool loadRelations = true) => GetAll(loadRelations).Where(p => productIds.Contains(p.Id));
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
using AyCode.Core.Loggers;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using FruitBank.Common.Dtos;
|
||||
using FruitBank.Common.Entities;
|
||||
using FruitBank.Common.Interfaces;
|
||||
using FruitBank.Common.Loggers;
|
||||
using FruitBank.Common.Server;
|
||||
using Humanizer;
|
||||
using Mango.Nop.Core.Loggers;
|
||||
using Mango.Nop.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -36,58 +39,83 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAcc, FruitBa
|
|||
{
|
||||
var product = eventMessage.Entity;
|
||||
|
||||
await SaveProductCustomAttributesAsync(eventMessage.Entity);
|
||||
var saveProductCustomAttributesResult = await SaveProductCustomAttributesAsync(eventMessage.Entity);
|
||||
|
||||
var isMeasurableProduct = await fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
//var isMeasurableProduct = await fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
|
||||
var shippingItems = await ctx.ShippingItems.Table
|
||||
.Where(si => si.ProductId == product.Id && !si.IsMeasured && si.IsMeasurable != isMeasurableProduct)
|
||||
.ToListAsync();
|
||||
if (saveProductCustomAttributesResult is { IsMeasurableChanged: true, IsMeasurable: not null })
|
||||
{
|
||||
var shippingItems = await ctx.ShippingItems.Table
|
||||
.Where(si => si.ProductId == product.Id && !si.IsMeasured && si.IsMeasurable != saveProductCustomAttributesResult.IsMeasurable.Value)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var shippingItem in shippingItems)
|
||||
shippingItem.IsMeasurable = isMeasurableProduct;
|
||||
if (shippingItems.Count > 0)
|
||||
{
|
||||
foreach (var shippingItem in shippingItems) shippingItem.IsMeasurable = saveProductCustomAttributesResult.IsMeasurable.Value;
|
||||
await ctx.ShippingItems.UpdateAsync(shippingItems, false);
|
||||
}
|
||||
}
|
||||
|
||||
await ctx.ShippingItems.UpdateAsync(shippingItems, false);
|
||||
await base.HandleEventAsync(eventMessage);
|
||||
}
|
||||
|
||||
public override async Task HandleEventAsync(EntityInsertedEvent<Product> eventMessage)
|
||||
{
|
||||
await SaveProductCustomAttributesAsync(eventMessage.Entity);
|
||||
await SaveProductCustomAttributesAsync(eventMessage.Entity); //TODO: ez ide miért kell? - J.
|
||||
await base.HandleEventAsync(eventMessage);
|
||||
}
|
||||
|
||||
private async Task SaveProductCustomAttributesAsync(Product product)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="product"></param>
|
||||
/// <returns>IsMeasureable</returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
|
||||
private async Task<(bool IsMeasurableChanged, bool? IsMeasurable)> SaveProductCustomAttributesAsync(Product product)
|
||||
{
|
||||
if (product == null) return;
|
||||
if (product == null) return (false, null);
|
||||
|
||||
var form = HttpContextAccessor.HttpContext?.Request?.Form;
|
||||
if (form == null || form.Count == 0) return;
|
||||
var hasForm = HttpContextAccessor.HttpContext?.Request?.HasFormContentType ?? false;
|
||||
var form = hasForm ? HttpContextAccessor.HttpContext.Request.Form : null;
|
||||
|
||||
if (form.ContainsKey(nameof(IMeasurable.IsMeasurable)) && form.ContainsKey(nameof(IMeasuringNetWeight.NetWeight)))
|
||||
if (form == null || form.Count == 0 ||
|
||||
!form.ContainsKey(nameof(IMeasurable.IsMeasurable)) || !form.ContainsKey(nameof(IMeasuringNetWeight.NetWeight)) ||
|
||||
!form.ContainsKey(nameof(IIncomingQuantity.IncomingQuantity)) || !form.ContainsKey(nameof(ITare.Tare))) return (false, null);
|
||||
|
||||
bool? isMeasurable = null;
|
||||
var isMeasurableChanged = false;
|
||||
|
||||
var productDto = product.Id > 0 ? await ctx.ProductDtos.GetByIdAsync(product.Id, false) : null;
|
||||
|
||||
//IsMeasurable
|
||||
isMeasurable = form[nameof(IMeasurable.IsMeasurable)].ToString().Contains("true");
|
||||
if (productDto == null || productDto.IsMeasurable != isMeasurable.Value)
|
||||
{
|
||||
var isMeasurable = form[nameof(IMeasurable.IsMeasurable)].ToString().Contains("true");
|
||||
//var isMeasurable = CommonHelper.To<bool>(form[nameof(IMeasurable.IsMeasurable)].ToString());
|
||||
var netWeight = CommonHelper.To<double>(form[nameof(IMeasuringNetWeight.NetWeight)].ToString());
|
||||
|
||||
await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, netWeight, 0, isMeasurable, false);
|
||||
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, bool>(product.Id, nameof(IMeasurable.IsMeasurable), isMeasurable.Value);
|
||||
isMeasurableChanged = true;
|
||||
}
|
||||
|
||||
if (form.ContainsKey(nameof(ITare.Tare)))
|
||||
{
|
||||
var tare = CommonHelper.To<double>(form[nameof(ITare.Tare)].ToString());
|
||||
if (tare < 0) throw new Exception($"FruitBankEventConsumer->SaveProductCustomAttributesAsync(); (tare < 0); productId: {product.Id}; tare: {tare}");
|
||||
//NetWeight
|
||||
var netWeight = double.Round(CommonHelper.To<double>(form[nameof(IMeasuringNetWeight.NetWeight)].ToString()), 1);
|
||||
if (productDto == null || productDto.NetWeight != netWeight)
|
||||
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight);
|
||||
|
||||
//Tára
|
||||
var tare = double.Round(CommonHelper.To<double>(form[nameof(ITare.Tare)].ToString()), 1);
|
||||
if (tare < 0) throw new Exception($"FruitBankEventConsumer->SaveProductCustomAttributesAsync(); (tare < 0); productId: {product.Id}; tare: {tare}");
|
||||
|
||||
if (productDto == null || productDto.Tare != tare)
|
||||
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(ITare.Tare), tare);
|
||||
}
|
||||
|
||||
if (form.ContainsKey(nameof(IIncomingQuantity.IncomingQuantity)))
|
||||
{
|
||||
var incomingQuantity = CommonHelper.To<int>(form[nameof(IIncomingQuantity.IncomingQuantity)].ToString());
|
||||
if (incomingQuantity < 0) throw new Exception($"FruitBankEventConsumer->SaveProductCustomAttributesAsync(); (incomingQuantity < 0); productId: {product.Id}; incomingQuantity: {incomingQuantity}");
|
||||
//IncomingQuantity
|
||||
var incomingQuantity = CommonHelper.To<int>(form[nameof(IIncomingQuantity.IncomingQuantity)].ToString());
|
||||
if (incomingQuantity < 0) throw new Exception($"FruitBankEventConsumer->SaveProductCustomAttributesAsync(); (incomingQuantity < 0); productId: {product.Id}; incomingQuantity: {incomingQuantity}");
|
||||
|
||||
if (productDto == null || productDto.IncomingQuantity != incomingQuantity)
|
||||
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, int>(product.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity);
|
||||
}
|
||||
|
||||
return (isMeasurableChanged, isMeasurable);
|
||||
}
|
||||
|
||||
public async Task HandleEventAsync(EntityInsertedEvent<ShippingItemPallet> eventMessage)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
|
|||
{
|
||||
public class CustomOrderModelFactory : MgOrderModelFactory<OrderListModelExtended, OrderModelExtended>
|
||||
{
|
||||
private FruitBankDbContext _ctx;
|
||||
private readonly FruitBankDbContext _ctx;
|
||||
private readonly IOrderMeasurementService _orderMeasurementService;
|
||||
|
||||
#region Ctor
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -162,7 +162,8 @@ public class MgOrderModelFactory<TOrderListModelExt, TOrderModelExt> : OrderMode
|
|||
|
||||
orderListModel.Data = null;
|
||||
|
||||
var orderListModelExtended = orderListModel.ToJson().JsonTo<TOrderListModelExt>();
|
||||
//var orderListModelExtended = orderListModel.ToJson().JsonTo<TOrderListModelExt>();
|
||||
var orderListModelExtended = orderListModel.CloneTo<TOrderListModelExt>();
|
||||
orderListModelExtended.Data = extendedRows;
|
||||
|
||||
return orderListModelExtended;
|
||||
|
|
|
|||
|
|
@ -156,7 +156,8 @@ public class MgProductModelFactory<TProductListModelExt, TProductModelExt> : Pro
|
|||
|
||||
productListModel.Data = null;
|
||||
|
||||
var productListModelExtended = productListModel.ToJson().JsonTo<TProductListModelExt>();
|
||||
//var productListModelExtended = productListModel.ToJson().JsonTo<TProductListModelExt>();
|
||||
var productListModelExtended = productListModel.CloneTo<TProductListModelExt>();
|
||||
productListModelExtended.Data = extendedRows;
|
||||
|
||||
return productListModelExtended;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
|
|||
public class FruitBankAttributeService(IGenericAttributeService genericAttributeService, IStoreContext storeContext)
|
||||
{
|
||||
private const string NET_WEIGHT_KEY = nameof(IMeasuringAttributeValues.NetWeight);
|
||||
private const string GROSS_WEIGHT_KEY = nameof(IMeasuringAttributeValues.GrossWeight);
|
||||
private const string IS_MEASURABLE_KEY = nameof(IMeasuringAttributeValues.IsMeasurable);
|
||||
|
||||
|
||||
|
|
@ -31,11 +30,11 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
|
|||
public async Task<List<GenericAttribute>?> GetMeasuringAttributesAsync<TEntity>(int entityId, int storeId)
|
||||
{
|
||||
var measuringAttributes = (await genericAttributeService.GetAttributesForEntityAsync(entityId, typeof(TEntity).Name))
|
||||
.Where(ga => ga.StoreId == storeId && ga.Key is NET_WEIGHT_KEY or GROSS_WEIGHT_KEY or IS_MEASURABLE_KEY)
|
||||
.Where(ga => ga.StoreId == storeId && ga.Key is NET_WEIGHT_KEY or IS_MEASURABLE_KEY)
|
||||
.ToList();
|
||||
|
||||
if (measuringAttributes.Count == 0) return null;
|
||||
if (measuringAttributes.Count != 3) throw new Exception($"FruitBankAttributeService->GetMeasuringAttributesAsync(); measuringAttributes.Count != 3; entityId: {entityId}");
|
||||
if (measuringAttributes.Count != 2) throw new Exception($"FruitBankAttributeService->GetMeasuringAttributesAsync(); measuringAttributes.Count != 2; entityId: {entityId}");
|
||||
|
||||
return measuringAttributes;
|
||||
}
|
||||
|
|
@ -51,7 +50,6 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
|
|||
var measuringAttributeValues = new MeasuringAttributeValues(
|
||||
entityId,
|
||||
CommonHelper.To<double>(measuringAttributes.Single(ga => ga.Key == NET_WEIGHT_KEY).Value),
|
||||
CommonHelper.To<double>(measuringAttributes.Single(ga => ga.Key == GROSS_WEIGHT_KEY).Value),
|
||||
CommonHelper.To<bool>(measuringAttributes.Single(ga => ga.Key == IS_MEASURABLE_KEY).Value));
|
||||
|
||||
return measuringAttributeValues;
|
||||
|
|
@ -64,13 +62,12 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
|
|||
return measurableAttribute != null && CommonHelper.To<bool>(measurableAttribute.Value);
|
||||
}
|
||||
|
||||
public async Task<MeasuringAttributeValues> InsertOrUpdateMeasuringAttributeValuesAsync<TEntity>(int entityId, double netWeight, double grossWeight, bool isMeasurable, bool cumulativeWeightUpdate)
|
||||
public async Task<MeasuringAttributeValues> InsertOrUpdateMeasuringAttributeValuesAsync<TEntity>(int entityId, double netWeight, bool isMeasurable, bool cumulativeWeightUpdate)
|
||||
{
|
||||
var measuringAttributeValues = new MeasuringAttributeValues
|
||||
{
|
||||
Id = entityId,
|
||||
NetWeight = netWeight,
|
||||
GrossWeight = grossWeight,
|
||||
IsMeasurable = isMeasurable
|
||||
};
|
||||
|
||||
|
|
@ -91,27 +88,15 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
|
|||
if (measuringAttributes == null)
|
||||
{
|
||||
await InsertGenericAttributeAsync<TEntity, double>(entityId, NET_WEIGHT_KEY, double.Round(measuringAttributeValues.NetWeight, 1), storeId);
|
||||
await InsertGenericAttributeAsync<TEntity, double>(entityId, GROSS_WEIGHT_KEY, double.Round(measuringAttributeValues.GrossWeight, 1), storeId);
|
||||
await InsertGenericAttributeAsync<TEntity, bool>(entityId, IS_MEASURABLE_KEY, measuringAttributeValues.IsMeasurable, storeId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await UpdateMeasuringWeightAttributeValueAsync(measuringAttributes.Single(ma => ma.Key == NET_WEIGHT_KEY), measuringAttributeValues.NetWeight, cumulativeWeightUpdate);
|
||||
await UpdateMeasuringWeightAttributeValueAsync(measuringAttributes.Single(ma => ma.Key == GROSS_WEIGHT_KEY), measuringAttributeValues.GrossWeight, cumulativeWeightUpdate);
|
||||
await UpdateGenericAttributeAsync(measuringAttributes.Single(ma => ma.Key == IS_MEASURABLE_KEY), measuringAttributeValues.IsMeasurable);
|
||||
|
||||
//var netWeightAttribute = measuringAttributes?.SingleOrDefault(ma => ma.Key == NET_WEIGHT_KEY);
|
||||
//if (netWeightAttribute != null) await UpdateMeasuringWeightAttributeValueAsync(netWeightAttribute, measuringAttributeValues.NetWeight, cumulativeWeightUpdate);
|
||||
//else await InsertGenericAttributeAsync<TEntity, double>(entityId, NET_WEIGHT_KEY, measuringAttributeValues.NetWeight, storeId);
|
||||
|
||||
//var grossWeightAttribute = measuringAttributes?.SingleOrDefault(ma => ma.Key == GROSS_WEIGHT_KEY);
|
||||
//if (grossWeightAttribute != null) await UpdateMeasuringWeightAttributeValueAsync(grossWeightAttribute, measuringAttributeValues.GrossWeight, cumulativeWeightUpdate);
|
||||
//else await InsertGenericAttributeAsync<TEntity, double>(entityId, GROSS_WEIGHT_KEY, measuringAttributeValues.GrossWeight, storeId);
|
||||
|
||||
//var isMeasurableAttribute = measuringAttributes?.SingleOrDefault(ma => ma.Key == IS_MEASURABLE_KEY);
|
||||
//if (isMeasurableAttribute != null) await UpdateGenericAttributeAsync(isMeasurableAttribute, measuringAttributeValues.IsMeasurable);
|
||||
//else await InsertGenericAttributeAsync<TEntity, bool>(entityId, IS_MEASURABLE_KEY, measuringAttributeValues.IsMeasurable, storeId);
|
||||
//TODO: ezzel mi legyen? - J.
|
||||
//await UpdateGenericAttributeAsync(measuringAttributes.Single(ma => ma.Key == IS_MEASURABLE_KEY), measuringAttributeValues.IsMeasurable);
|
||||
}
|
||||
|
||||
private async Task UpdateMeasuringWeightAttributeValueAsync(GenericAttribute genericAttribute, double newWeightValue, bool cumulativeWeightUpdate)
|
||||
|
|
|
|||
Loading…
Reference in New Issue