nopSolutions / nopCommerce

ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
https://www.nopcommerce.com
Other
9.21k stars 5.29k forks source link

Incorrect change of order item price in admin area #7229

Closed RomanovM closed 3 months ago

RomanovM commented 3 months ago

nopCommerce version: 4.70

Set AutoUpdateOrderTotalsOnEditingOrder=True Open the order in nop admin mode and change the price for the order item. The order total will be recalculated, but the order item price will be the same.

Set AutoUpdateOrderTotalsOnEditingOrder=False Open the order in nop admin mode and change the price for the order item. The order total will not be recalculated, but the order item price will be changed.

OrderProcessingService.cs public virtual async Task UpdateOrderTotalsAsync(UpdateOrderParameters updateOrderParameters)

Add the next lines

            if (!itemDeleted)
            {
                var product = await _productService.GetProductByIdAsync(updatedShoppingCartItem.ProductId);
                var store = await _storeService.GetStoreByIdAsync(updatedShoppingCartItem.StoreId);

                updateOrderParameters.Warnings.AddRange(await _shoppingCartService.GetShoppingCartItemWarningsAsync(customer, updatedShoppingCartItem.ShoppingCartType,
                    product, updatedOrder.StoreId, updatedShoppingCartItem.AttributesXml, updatedShoppingCartItem.CustomerEnteredPrice,
                    updatedShoppingCartItem.RentalStartDateUtc, updatedShoppingCartItem.RentalEndDateUtc, updatedShoppingCartItem.Quantity, false, updatedShoppingCartItem.Id));

                updatedOrderItem.ItemWeight = await _shippingService.GetShoppingCartItemWeightAsync(updatedShoppingCartItem);
                updatedOrderItem.OriginalProductCost = await _priceCalculationService.GetProductCostAsync(product, updatedShoppingCartItem.AttributesXml);
                updatedOrderItem.AttributeDescription = await _productAttributeFormatter.FormatAttributesAsync(product,
                    updatedShoppingCartItem.AttributesXml, customer, store);

                //gift cards
                await AddGiftCardsAsync(product, updatedShoppingCartItem.AttributesXml, updatedShoppingCartItem.Quantity, updatedOrderItem, updatedOrderItem.UnitPriceExclTax);
            }

            await _orderTotalCalculationService.UpdateOrderTotalsAsync(updateOrderParameters, restoredCart);

            if (!itemDeleted)
                await _orderService.UpdateOrderItemAsync(updatedOrderItem);

Source: https://www.nopcommerce.com/boards/topic/99293/bug-dont-change-the-price-of-the-order-item-in-nop-admin-mode

See also: #8

skoshelev commented 3 months ago

Closed #7229