Discount unitprice fix

This commit is contained in:
Loretta 2025-11-20 09:18:16 +01:00
parent dd0d4f2097
commit f71acbf562
1 changed files with 32 additions and 14 deletions

View File

@ -547,16 +547,28 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
throw new Exception($"{errorText}"); throw new Exception($"{errorText}");
} }
var valami = await _priceCalculationService.GetFinalPriceAsync(product, customer, store, includeDiscounts: true);
var unitPrice = valami.finalPrice;
// Calculate tax
var (unitPriceInclTaxValue, _) = await _taxService.GetProductPriceAsync(product, unitPrice, true, customer);
var (unitPriceExclTaxValue, _) = await _taxService.GetProductPriceAsync(product, unitPrice, false, customer);
var orderItem = new OrderItem var orderItem = new OrderItem
{ {
OrderId = order.Id, OrderId = order.Id,
ProductId = item.Id, ProductId = item.Id,
Quantity = item.Quantity, Quantity = item.Quantity,
UnitPriceInclTax = item.Price,
UnitPriceExclTax = item.Price, UnitPriceInclTax = unitPriceInclTaxValue,
PriceInclTax = isMeasurable ? 0 : item.Price * item.Quantity, UnitPriceExclTax = unitPriceExclTaxValue,
PriceExclTax = isMeasurable ? 0 : item.Price * item.Quantity,
OriginalProductCost = product.ProductCost, PriceInclTax = isMeasurable ? 0 : unitPriceInclTaxValue * item.Quantity,
PriceExclTax = isMeasurable ? 0 : unitPriceExclTaxValue * item.Quantity,
OriginalProductCost = await _priceCalculationService.GetProductCostAsync(product, null),
AttributeDescription = string.Empty, AttributeDescription = string.Empty,
AttributesXml = string.Empty, AttributesXml = string.Empty,
DiscountAmountInclTax = 0, DiscountAmountInclTax = 0,
@ -1215,6 +1227,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
} }
var productDtosByOrderItemId = await _dbContext.ProductDtos.GetAllByIds(products.Select(x => x.Id).ToArray()).ToDictionaryAsync(k => k.Id, v => v); var productDtosByOrderItemId = await _dbContext.ProductDtos.GetAllByIds(products.Select(x => x.Id).ToArray()).ToDictionaryAsync(k => k.Id, v => v);
var customer = await _customerService.GetCustomerByIdAsync(order.CustomerId); var customer = await _customerService.GetCustomerByIdAsync(order.CustomerId);
var store = await _storeContext.GetCurrentStoreAsync(); var store = await _storeContext.GetCurrentStoreAsync();
var admin = await _workContext.GetCurrentCustomerAsync(); var admin = await _workContext.GetCurrentCustomerAsync();
@ -1222,8 +1235,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
var transactionSuccess = await _dbContext.TransactionSafeAsync(async _ => var transactionSuccess = await _dbContext.TransactionSafeAsync(async _ =>
{ {
// Add each product to the order // Add each product to the order
foreach (var productModel in products) foreach (var productModel in products)
{ {
@ -1237,7 +1248,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
// Validate stock // Validate stock
//var stockQuantity = await _productService.GetTotalStockQuantityAsync(product); //var stockQuantity = await _productService.GetTotalStockQuantityAsync(product);
var productDto = productDtosByOrderItemId[productModel.Id]; var productDto = productDtosByOrderItemId[productModel.Id];
//var isMeasurable = productDto.IsMeasurable; var isMeasurable = productDto.IsMeasurable;
//if (stockQuantity < productModel.Quantity) //if (stockQuantity < productModel.Quantity)
//{ //{
@ -1264,9 +1275,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
var valami = await _priceCalculationService.GetFinalPriceAsync(product, customer, store, includeDiscounts: true); var valami = await _priceCalculationService.GetFinalPriceAsync(product, customer, store, includeDiscounts: true);
var originalPrice = valami.priceWithoutDiscounts;
var discountAmount = valami.appliedDiscountAmount;
var discountedPrice = valami.appliedDiscounts;
var unitPrice = valami.finalPrice; var unitPrice = valami.finalPrice;
// Calculate tax // Calculate tax
@ -1279,12 +1287,22 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
OrderItemGuid = Guid.NewGuid(), OrderItemGuid = Guid.NewGuid(),
OrderId = order.Id, OrderId = order.Id,
ProductId = product.Id, ProductId = product.Id,
Quantity = productModel.Quantity,
UnitPriceInclTax = unitPriceInclTaxValue, UnitPriceInclTax = unitPriceInclTaxValue,
UnitPriceExclTax = unitPriceExclTaxValue, UnitPriceExclTax = unitPriceExclTaxValue,
PriceInclTax = unitPriceInclTaxValue * productModel.Quantity,
PriceExclTax = unitPriceExclTaxValue * productModel.Quantity, PriceInclTax = isMeasurable ? 0 : unitPriceInclTaxValue * productModel.Quantity,
PriceExclTax = isMeasurable ? 0 : unitPriceExclTaxValue * productModel.Quantity,
OriginalProductCost = await _priceCalculationService.GetProductCostAsync(product, null), OriginalProductCost = await _priceCalculationService.GetProductCostAsync(product, null),
Quantity = productModel.Quantity,
//UnitPriceInclTax = unitPriceInclTaxValue,
//UnitPriceExclTax = unitPriceExclTaxValue,
//PriceInclTax = unitPriceInclTaxValue * productModel.Quantity,
//PriceExclTax = unitPriceExclTaxValue * productModel.Quantity,
//OriginalProductCost = await _priceCalculationService.GetProductCostAsync(product, null),
DiscountAmountInclTax = decimal.Zero, DiscountAmountInclTax = decimal.Zero,
DiscountAmountExclTax = decimal.Zero, DiscountAmountExclTax = decimal.Zero,
DownloadCount = 0, DownloadCount = 0,