diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs index a2bf204..3474ada 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs @@ -547,16 +547,28 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers 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 { OrderId = order.Id, ProductId = item.Id, Quantity = item.Quantity, - UnitPriceInclTax = item.Price, - UnitPriceExclTax = item.Price, - PriceInclTax = isMeasurable ? 0 : item.Price * item.Quantity, - PriceExclTax = isMeasurable ? 0 : item.Price * item.Quantity, - OriginalProductCost = product.ProductCost, + + UnitPriceInclTax = unitPriceInclTaxValue, + UnitPriceExclTax = unitPriceExclTaxValue, + + PriceInclTax = isMeasurable ? 0 : unitPriceInclTaxValue * item.Quantity, + PriceExclTax = isMeasurable ? 0 : unitPriceExclTaxValue * item.Quantity, + + OriginalProductCost = await _priceCalculationService.GetProductCostAsync(product, null), + AttributeDescription = string.Empty, AttributesXml = string.Empty, 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 customer = await _customerService.GetCustomerByIdAsync(order.CustomerId); var store = await _storeContext.GetCurrentStoreAsync(); var admin = await _workContext.GetCurrentCustomerAsync(); @@ -1222,8 +1235,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers var transactionSuccess = await _dbContext.TransactionSafeAsync(async _ => { - - // Add each product to the order foreach (var productModel in products) { @@ -1237,7 +1248,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers // Validate stock //var stockQuantity = await _productService.GetTotalStockQuantityAsync(product); var productDto = productDtosByOrderItemId[productModel.Id]; - //var isMeasurable = productDto.IsMeasurable; + var isMeasurable = productDto.IsMeasurable; //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 originalPrice = valami.priceWithoutDiscounts; - var discountAmount = valami.appliedDiscountAmount; - var discountedPrice = valami.appliedDiscounts; var unitPrice = valami.finalPrice; // Calculate tax @@ -1279,12 +1287,22 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers OrderItemGuid = Guid.NewGuid(), OrderId = order.Id, ProductId = product.Id, + Quantity = productModel.Quantity, + UnitPriceInclTax = unitPriceInclTaxValue, 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), - Quantity = productModel.Quantity, + + //UnitPriceInclTax = unitPriceInclTaxValue, + //UnitPriceExclTax = unitPriceExclTaxValue, + //PriceInclTax = unitPriceInclTaxValue * productModel.Quantity, + //PriceExclTax = unitPriceExclTaxValue * productModel.Quantity, + //OriginalProductCost = await _priceCalculationService.GetProductCostAsync(product, null), + DiscountAmountInclTax = decimal.Zero, DiscountAmountExclTax = decimal.Zero, DownloadCount = 0,