Compare commits
5 Commits
6735765821
...
1d19bd0e37
| Author | SHA1 | Date |
|---|---|---|
|
|
1d19bd0e37 | |
|
|
16cd9ccd73 | |
|
|
11651e4946 | |
|
|
05d9c97645 | |
|
|
3b2af72d5e |
|
|
@ -325,7 +325,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
||||||
|
|
||||||
//var productDtosById = await _dbContext.ProductDtos.GetAllByIds(orderProducts.Select(op => op.Id)).ToDictionaryAsync(p => p.Id, prodDto => prodDto);
|
//var productDtosById = await _dbContext.ProductDtos.GetAllByIds(orderProducts.Select(op => op.Id)).ToDictionaryAsync(p => p.Id, prodDto => prodDto);
|
||||||
var store = _storeContext.GetCurrentStore();
|
var store = _storeContext.GetCurrentStore();
|
||||||
var productDtosByOrderItemId = (await _dbContext.ProductDtos.GetAllByIds(orderProducts.Select(x => x.Id).ToArray()).ToListAsync()).ToDictionary(k => k.Id, v => v);
|
var productDtosByOrderItemId = await _dbContext.ProductDtos.GetAllByIds(orderProducts.Select(x => x.Id).ToArray()).ToDictionaryAsync(k => k.Id, v => v);
|
||||||
|
|
||||||
var transactionSuccess = await _dbContext.TransactionSafeAsync(async _ =>
|
var transactionSuccess = await _dbContext.TransactionSafeAsync(async _ =>
|
||||||
{
|
{
|
||||||
|
|
@ -336,10 +336,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
||||||
foreach (var item in orderProducts)
|
foreach (var item in orderProducts)
|
||||||
{
|
{
|
||||||
var product = await _productService.GetProductByIdAsync(item.Id);
|
var product = await _productService.GetProductByIdAsync(item.Id);
|
||||||
|
if (product == null)
|
||||||
if (product == null || product.StockQuantity - item.Quantity < 0)
|
|
||||||
{
|
{
|
||||||
var errorText = $"product == null || product.StockQuantity - item.Quantity < 0; productId: {product?.Id}; product?.StockQuantity - item.Quantity: {product?.StockQuantity - item.Quantity}";
|
var errorText = $"product == null; productId: {item.Id};";
|
||||||
|
|
||||||
_logger.Error($"{errorText}");
|
_logger.Error($"{errorText}");
|
||||||
throw new Exception($"{errorText}");
|
throw new Exception($"{errorText}");
|
||||||
|
|
@ -348,6 +347,14 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
||||||
var productDto = productDtosByOrderItemId[item.Id];
|
var productDto = productDtosByOrderItemId[item.Id];
|
||||||
var isMeasurable = productDto.IsMeasurable;
|
var isMeasurable = productDto.IsMeasurable;
|
||||||
|
|
||||||
|
if ((product.StockQuantity + productDto.IncomingQuantity) - item.Quantity < 0)
|
||||||
|
{
|
||||||
|
var errorText = $"((product.StockQuantity + productDto.IncomingQuantity) - item.Quantity < 0); productId: {product.Id}; (product.StockQuantity + productDto.IncomingQuantity) - item.Quantity: {(product.StockQuantity + productDto.IncomingQuantity) - item.Quantity}";
|
||||||
|
|
||||||
|
_logger.Error($"{errorText}");
|
||||||
|
throw new Exception($"{errorText}");
|
||||||
|
}
|
||||||
|
|
||||||
var orderItem = new OrderItem
|
var orderItem = new OrderItem
|
||||||
{
|
{
|
||||||
OrderId = order.Id,
|
OrderId = order.Id,
|
||||||
|
|
@ -562,15 +569,20 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
||||||
pageSize: maxResults);
|
pageSize: maxResults);
|
||||||
|
|
||||||
var result = new List<object>();
|
var result = new List<object>();
|
||||||
|
var productDtosById = await _dbContext.ProductDtos.GetAllByIds(products.Select(p => p.Id)).ToDictionaryAsync(k => k.Id, v => v);
|
||||||
|
|
||||||
foreach (var product in products)
|
foreach (var product in products)
|
||||||
{
|
{
|
||||||
|
var productDto = productDtosById[product.Id];
|
||||||
|
|
||||||
result.Add(new
|
result.Add(new
|
||||||
{
|
{
|
||||||
label = $"{product.Name} [KÉSZLET: {product.StockQuantity}] [ÁR: {product.Price}]",
|
label = $"{product.Name} [RENDELHETŐ: {(product.StockQuantity + productDto.IncomingQuantity)}] [ÁR: {product.Price}]",
|
||||||
value = product.Id,
|
value = product.Id,
|
||||||
sku = product.Sku,
|
sku = product.Sku,
|
||||||
price = product.Price,
|
price = product.Price,
|
||||||
stockQuantity = product.StockQuantity
|
stockQuantity = product.StockQuantity,
|
||||||
|
incomingQuantity = productDto.IncomingQuantity,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,16 @@ using FruitBank.Common.SignalRs;
|
||||||
using Mango.Nop.Core.Loggers;
|
using Mango.Nop.Core.Loggers;
|
||||||
using Nop.Core;
|
using Nop.Core;
|
||||||
using Nop.Core.Domain.Orders;
|
using Nop.Core.Domain.Orders;
|
||||||
|
using Nop.Core.Events;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Controllers;
|
using Nop.Plugin.Misc.FruitBankPlugin.Controllers;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||||
|
using Nop.Services.Catalog;
|
||||||
|
using static Nop.Services.Security.StandardPermission;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
|
||||||
|
|
||||||
public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IWorkContext workContext, IEnumerable<IAcLogWriterBase> logWriters) : ICustomOrderSignalREndpointServer
|
public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IPriceCalculationService customPriceCalculationService,IEventPublisher eventPublisher, IWorkContext workContext, IEnumerable<IAcLogWriterBase> logWriters) : ICustomOrderSignalREndpointServer
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = new Logger<CustomOrderSignalREndpoint>(logWriters.ToArray());
|
private readonly ILogger _logger = new Logger<CustomOrderSignalREndpoint>(logWriters.ToArray());
|
||||||
|
|
||||||
|
|
@ -61,7 +65,17 @@ public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IWorkContext wor
|
||||||
{
|
{
|
||||||
_logger.Detail($"SetOrderStatusToComplete invoked; orderId: {orderId}; revisorId: {revisorId}");
|
_logger.Detail($"SetOrderStatusToComplete invoked; orderId: {orderId}; revisorId: {revisorId}");
|
||||||
|
|
||||||
if (!await ctx.SetOrderStatusToCompleteSafeAsync(orderId, revisorId)) return null;
|
//TODO: Ez egész nagyon kusza, átgondolni és refaktorálni! - J.
|
||||||
|
var order = ctx.Orders.GetById(orderId);
|
||||||
|
var prevOrderStatus = order.OrderStatus;
|
||||||
|
|
||||||
|
if (order.OrderStatus == OrderStatus.Complete || !await ctx.SetOrderStatusToCompleteSafeAsync(orderId, revisorId)) return null;
|
||||||
|
|
||||||
|
order.OrderStatus = OrderStatus.Complete;
|
||||||
|
await ((CustomPriceCalculationService)customPriceCalculationService).CheckAndUpdateOrderTotalPrice(order);
|
||||||
|
|
||||||
|
if (prevOrderStatus != order.OrderStatus) await eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus));
|
||||||
|
|
||||||
return await ctx.OrderDtos.GetByIdAsync(orderId, true);
|
return await ctx.OrderDtos.GetByIdAsync(orderId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,11 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
|
||||||
|
|
||||||
private async Task OrderTotalsFix()
|
private async Task OrderTotalsFix()
|
||||||
{
|
{
|
||||||
var orders = await _dbContext.Orders.Table.ToListAsync();
|
//var orders = await _dbContext.Orders.Table.ToListAsync();
|
||||||
foreach (var order in orders)
|
//foreach (var order in orders)
|
||||||
{
|
//{
|
||||||
await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
|
// await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> Test()
|
public async Task<IActionResult> Test()
|
||||||
|
|
|
||||||
|
|
@ -763,7 +763,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Product</th>
|
<th>Product</th>
|
||||||
<th style="width: 100px;">Mennyisség</th>
|
<th style="width: 100px;">Mennyiség</th>
|
||||||
<th style="width: 120px;">Egységár</th>
|
<th style="width: 120px;">Egységár</th>
|
||||||
<th style="width: 50px;"></th>
|
<th style="width: 50px;"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -860,6 +860,7 @@
|
||||||
sku: product.sku || '',
|
sku: product.sku || '',
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
stockQuantity : product.stockQuantity,
|
stockQuantity : product.stockQuantity,
|
||||||
|
incomingQuantity : product.incomingQuantity,
|
||||||
price: product.price || 0
|
price: product.price || 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -889,7 +890,7 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
var quantityCell = $('<td>').html(
|
var quantityCell = $('<td>').html(
|
||||||
'<input type="number" class="form-control form-control-sm" min="1" max="' + product.stockQuantity + '" value="' + product.quantity + '" data-index="' + index + '" />'
|
'<input type="number" class="form-control form-control-sm" min="1" max="' + (product.stockQuantity + product.incomingQuantity) + '" value="' + product.quantity + '" data-index="' + index + '" />'
|
||||||
);
|
);
|
||||||
|
|
||||||
var priceCell = $('<td>').html(
|
var priceCell = $('<td>').html(
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@
|
||||||
var discountInclTax = parseFloat($('#pvDiscountInclTax'+itemId).val()) || 0;
|
var discountInclTax = parseFloat($('#pvDiscountInclTax'+itemId).val()) || 0;
|
||||||
var discountExclTax = parseFloat($('#pvDiscountExclTax'+itemId).val()) || 0;
|
var discountExclTax = parseFloat($('#pvDiscountExclTax'+itemId).val()) || 0;
|
||||||
|
|
||||||
|
//if (maxQuantity < currentQuantity) maxQuantity = currentQuantity;
|
||||||
|
//console.log(maxQuantity);
|
||||||
|
|
||||||
if (quantity > maxQuantity || quantity < 1) {
|
if (quantity > maxQuantity || quantity < 1) {
|
||||||
if (quantity > maxQuantity) quantity = maxQuantity; else quantity = 1;
|
if (quantity > maxQuantity) quantity = maxQuantity; else quantity = 1;
|
||||||
$('#pvQuantity' + itemId).val(quantity);
|
$('#pvQuantity' + itemId).val(quantity);
|
||||||
|
|
@ -101,7 +104,7 @@
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
toggleOrderItemEditGlobal(false, @(item.Id));
|
toggleOrderItemEditGlobal(false, @(item.Id));
|
||||||
setupAutoCalculationGlobal(@(item.Id), @(item.ProductStockQuantity + item.ProductIncomingQuantity + item.Quantity));
|
setupAutoCalculationGlobal(@(item.Id), @(Math.Max(item.ProductStockQuantity + item.ProductIncomingQuantity + item.Quantity, item.Quantity)));
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
|
@ -291,7 +294,7 @@
|
||||||
<div id="pnlEditPvQuantity@(item.Id)">
|
<div id="pnlEditPvQuantity@(item.Id)">
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<div class="col-md-8 offset-md-2">
|
<div class="col-md-8 offset-md-2">
|
||||||
<input name="pvQuantity@(item.Id)" type="number" max="@(item.ProductStockQuantity + item.ProductIncomingQuantity + item.Quantity)" min="1"
|
<input name="pvQuantity@(item.Id)" type="number" max="@(Math.Max(item.ProductStockQuantity + item.ProductIncomingQuantity + item.Quantity, item.Quantity))" min="1"
|
||||||
value="@item.Quantity" id="pvQuantity@(item.Id)" class="form-control input-sm" />
|
value="@item.Quantity" id="pvQuantity@(item.Id)" class="form-control input-sm" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -417,7 +417,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
|
|
||||||
if (!orderDto.IsMeasuredAndValid() || orderDto.OrderStatus == OrderStatus.Complete) return null; //throw new Exception($"SetOrderDtoToComplete; orderDto.IsMeasured == false; {orderDto}");
|
if (!orderDto.IsMeasuredAndValid() || orderDto.OrderStatus == OrderStatus.Complete) return null; //throw new Exception($"SetOrderDtoToComplete; orderDto.IsMeasured == false; {orderDto}");
|
||||||
|
|
||||||
var prevOrderStatus = orderDto.OrderStatus;
|
//var prevOrderStatus = orderDto.OrderStatus;
|
||||||
orderDto.OrderStatus = OrderStatus.Complete;
|
orderDto.OrderStatus = OrderStatus.Complete;
|
||||||
|
|
||||||
await OrderDtos.UpdateAsync(orderDto);
|
await OrderDtos.UpdateAsync(orderDto);
|
||||||
|
|
@ -433,9 +433,6 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
|
|
||||||
if (!orderItemDto.IsMeasurable) continue;
|
if (!orderItemDto.IsMeasurable) continue;
|
||||||
|
|
||||||
var finalPriceInclTax = decimal.Round(orderItemDto.UnitPriceInclTax * orderItemDto.Quantity, 0);
|
|
||||||
var finalPriceExclTax = decimal.Round(orderItemDto.UnitPriceExclTax * orderItemDto.Quantity, 0);
|
|
||||||
|
|
||||||
var gaNetWeight = CommonHelper.To<double>(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0");
|
var gaNetWeight = CommonHelper.To<double>(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0");
|
||||||
|
|
||||||
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<OrderItem, double>
|
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<OrderItem, double>
|
||||||
|
|
@ -444,10 +441,8 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>
|
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>
|
||||||
(orderItemDto.ProductId, -(orderItemDto.NetWeight-gaNetWeight), orderItemDto.IsMeasurable, true);
|
(orderItemDto.ProductId, -(orderItemDto.NetWeight-gaNetWeight), orderItemDto.IsMeasurable, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var order = Orders.GetById(orderDto.Id);
|
//await _eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus));
|
||||||
await _eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus));
|
|
||||||
|
|
||||||
return orderDto;
|
return orderDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ public class CustomPriceCalculationService : PriceCalculationService
|
||||||
productAttributeParser, productService,
|
productAttributeParser, productService,
|
||||||
cacheManager)
|
cacheManager)
|
||||||
{
|
{
|
||||||
_logger = new Logger(logWriters.ToArray());
|
_logger = new Logger<CustomPriceCalculationService>(logWriters.ToArray());
|
||||||
|
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
// assign all base deps to local private vars if needed
|
// assign all base deps to local private vars if needed
|
||||||
|
|
@ -60,41 +60,49 @@ public class CustomPriceCalculationService : PriceCalculationService
|
||||||
_localizationService = localizationService;
|
_localizationService = localizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public decimal CalculateOrderItemFinalPrice(OrderItemDto orderItemDto, decimal unitPrice, int quantity)
|
public static decimal CalculateOrderItemFinalPrice(bool isMeasurable, decimal unitPrice, int quantity, double netWeight)
|
||||||
=> decimal.Round(unitPrice * (orderItemDto.IsMeasurable ? (decimal)orderItemDto.NetWeight : quantity), 0);
|
=> decimal.Round(unitPrice * (isMeasurable ? (decimal)netWeight: quantity), 0);
|
||||||
|
|
||||||
|
private static (decimal finalPriceInclTax, decimal finalPriceExclTax) CalculateOrderItemFinalPrices(int quantity, decimal unitPriceInclTax, decimal unitPriceExclTax, bool isMeasurable, double netWeight)
|
||||||
|
{
|
||||||
|
var finalPriceInclTax = CalculateOrderItemFinalPrice(isMeasurable, unitPriceInclTax, quantity, netWeight);
|
||||||
|
var finalPriceExclTax = CalculateOrderItemFinalPrice(isMeasurable, unitPriceExclTax, quantity, netWeight);
|
||||||
|
|
||||||
|
return (finalPriceInclTax, finalPriceExclTax);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem)
|
public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem)
|
||||||
{
|
{
|
||||||
var orderItemDto = await _dbContext.OrderItemDtos.GetByIdAsync(orderItem.Id, true);
|
var orderItemDto = await _dbContext.OrderItemDtos.GetByIdAsync(orderItem.Id, true);
|
||||||
return await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDto);
|
return await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDto.IsMeasurable, orderItemDto.NetWeight);
|
||||||
}
|
|
||||||
public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItemDto orderItemDto)
|
|
||||||
{
|
|
||||||
var orderItem = await _dbContext.OrderItems.GetByIdAsync(orderItemDto.Id);
|
|
||||||
return await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItemDto orderItemDto)
|
||||||
|
//{
|
||||||
|
// var orderItem = await _dbContext.OrderItems.GetByIdAsync(orderItemDto.Id);
|
||||||
|
// return await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDto.IsMeasurable, orderItemDto.NetWeight);
|
||||||
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="orderItem"></param>
|
/// <param name="orderItem"></param>
|
||||||
/// <param name="orderItemDto"></param>
|
/// <param name="isMeasurable"></param>
|
||||||
|
/// /// <param name="netWeight"></param>
|
||||||
/// <returns>true if has changes</returns>
|
/// <returns>true if has changes</returns>
|
||||||
public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem, OrderItemDto orderItemDto)
|
public async Task<bool> CheckAndUpdateOrderItemFinalPricesAsync(OrderItem orderItem, bool isMeasurable, double netWeight)
|
||||||
{
|
{
|
||||||
_logger.Info($"CustomPriceCalculationService->CheckAndUpdateOrderItemFinalPricesAsync; orderItem.Id: {orderItem.Id}");
|
_logger.Info($"orderItem.Id: {orderItem.Id}");
|
||||||
|
|
||||||
var finalPriceInclTax = CalculateOrderItemFinalPrice(orderItemDto, orderItem.UnitPriceInclTax, orderItem.Quantity);
|
var finalPrices = CalculateOrderItemFinalPrices(orderItem.Quantity, orderItem.UnitPriceInclTax, orderItem.UnitPriceExclTax, isMeasurable, netWeight);
|
||||||
var finalPriceExclTax = CalculateOrderItemFinalPrice(orderItemDto, orderItem.UnitPriceExclTax, orderItem.Quantity);
|
|
||||||
|
|
||||||
if (orderItem.PriceInclTax == finalPriceInclTax && orderItem.PriceExclTax == finalPriceExclTax) return false;
|
if (finalPrices.finalPriceInclTax == orderItem.PriceInclTax && finalPrices.finalPriceExclTax == orderItem.PriceExclTax) return false;
|
||||||
|
|
||||||
_logger.Error($"CustomPriceCalculationService->CheckAndUpdateOrderItemFinalPricesAsync; " +
|
_logger.Info($"orderItem.PriceInclTax({orderItem.PriceInclTax}) != finalPriceInclTax({finalPrices.finalPriceInclTax}) || " +
|
||||||
$"orderItem.PriceInclTax({orderItem.PriceInclTax}) != finalPriceInclTax({finalPriceInclTax}) || " +
|
$"orderItem.PriceExclTax({orderItem.PriceExclTax}) != finalPriceExclTax({finalPrices.finalPriceExclTax})");
|
||||||
$"orderItem.PriceExclTax({orderItem.PriceExclTax}) != finalPriceExclTax({finalPriceExclTax})");
|
|
||||||
|
|
||||||
orderItem.PriceInclTax = finalPriceInclTax;
|
orderItem.PriceInclTax = finalPrices.finalPriceInclTax;
|
||||||
orderItem.PriceExclTax = finalPriceExclTax;
|
orderItem.PriceExclTax = finalPrices.finalPriceExclTax;
|
||||||
|
|
||||||
await _dbContext.OrderItems.UpdateAsync(orderItem, false);
|
await _dbContext.OrderItems.UpdateAsync(orderItem, false);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -108,26 +116,30 @@ public class CustomPriceCalculationService : PriceCalculationService
|
||||||
public async Task<bool> CheckAndUpdateOrderTotalPrice(Order order)
|
public async Task<bool> CheckAndUpdateOrderTotalPrice(Order order)
|
||||||
{
|
{
|
||||||
var prevOrderTotal = order.OrderTotal;
|
var prevOrderTotal = order.OrderTotal;
|
||||||
var orderItemDtos = await _dbContext.OrderItemDtos.GetAllByOrderId(order.Id).ToListAsync();
|
|
||||||
|
var orderItemDtosById = await _dbContext.OrderItemDtos.GetAllByOrderId(order.Id).ToDictionaryAsync(k => k.Id, v => v);
|
||||||
|
var orderItems = await _dbContext.OrderItems.GetByIdsAsync(orderItemDtosById.Keys.ToList());
|
||||||
|
|
||||||
order.OrderTotal = 0;
|
order.OrderTotal = 0;
|
||||||
|
|
||||||
foreach (var itemDto in orderItemDtos)
|
foreach (var orderItem in orderItems)
|
||||||
{
|
{
|
||||||
await CheckAndUpdateOrderItemFinalPricesAsync(itemDto);
|
var orderItemDto = orderItemDtosById[orderItem.Id];
|
||||||
order.OrderTotal += itemDto.PriceInclTax;
|
|
||||||
|
await CheckAndUpdateOrderItemFinalPricesAsync(orderItem, orderItemDto.IsMeasurable, orderItemDto.NetWeight);
|
||||||
|
order.OrderTotal += orderItem.PriceInclTax;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (order.OrderTotal == prevOrderTotal) return false;
|
if (order.OrderTotal == prevOrderTotal) return false;
|
||||||
|
|
||||||
_logger.Error($"HandleEventAsync->CheckAndUpdateOrderItemFinalPrices; order.OrderTotal({order.OrderTotal}) == prevOrderTotal({prevOrderTotal})");
|
_logger.Error($"order.OrderTotal({order.OrderTotal}) == prevOrderTotal({prevOrderTotal})");
|
||||||
|
|
||||||
order.OrderSubtotalInclTax = order.OrderTotal;
|
order.OrderSubtotalInclTax = order.OrderTotal;
|
||||||
order.OrderSubtotalExclTax = order.OrderTotal;
|
order.OrderSubtotalExclTax = order.OrderTotal;
|
||||||
order.OrderSubTotalDiscountInclTax = order.OrderTotal;
|
order.OrderSubTotalDiscountInclTax = order.OrderTotal;
|
||||||
order.OrderSubTotalDiscountExclTax = order.OrderTotal;
|
order.OrderSubTotalDiscountExclTax = order.OrderTotal;
|
||||||
|
|
||||||
await _dbContext.Orders.UpdateAsync(order);
|
await _dbContext.Orders.UpdateAsync(order, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue