在后端magento中编辑订单时价格不正确

I have a problem when editing an order in the back-end of Magento. In the front end, I have custom price when add Product to cart. Price is good in back end ( show and correct in order) but when I click edit order, the price is not correct in Item order. I have seen it get the default price of product. I try to catch event sales_quote_save_before and try code

$quote = $observer->getEvent()->getQuote(); 
foreach ($quote->getAllItems() as $item)
{
 $item->setCustomPrice($price);
 $item->setOriginalCustomPrice($price);
} 

but I only set custom price for each item in order, I can not set Subtotal and row Subtotal for order. could you tell me how to do that? Thank so much

You can programmatically set subtotals and other related attributes as following:

$order = Mage::getModel('sales/order')->setIncrementId($reservedOrderId)->setStoreId($storeId); // if saving new one

$order = Mage::getModel('sales/order')->loadByIncrementId('10012345');    //if loading product
$order->setSubtotal($sub_total)
$order->setBaseSubtotal($base_sub_total)
$order->setTaxAmount($some_tax_price)
$order->setGrandTotal($grand_total)
$order->setBaseGrandTotal($base_grand_total);

Do note that if you make changes in this manner then some reports might not calculate the order(s) correctly (such as dashboard)

Can try following solution -

Can create solution via Magento module

1) config.xml, need add block with event sales_convert_order_item_to_quote_item - like

<adminhtml>
    <events>
        <sales_convert_order_item_to_quote_item>
            <observers>
                <orderpricesfromoldorder_old_prices>
                    <type>singleton</type>
                    <class>Magefast_OrderPricesFromOldOrder_Model_Observer</class>
                    <method>salesEventOrderItemToQuoteItemPrices</method>
                </orderpricesfromoldorder_old_prices>
            </observers>
        </sales_convert_order_item_to_quote_item>
    </events>
</adminhtml>

2) Observer file with function/method - like

public function salesEventOrderItemToQuoteItemPrices($observer)
{

    /** @var $orderItem Mage_Sales_Model_Order_Item */
    $orderItem = $observer->getEvent()->getOrderItem();
    $quoteItem = $observer->getEvent()->getQuoteItem();
    // Do not import giftmessage data if order is reordered
    $order = $orderItem->getOrder();
    if ($order && $order->getReordered()) {
        return $this;
    }

    // mage::log($orderItem->getData('price'));
    // mage::log($quoteItem->getProduct()->getData('price'));

    if ($orderItem->getData('price') && $orderItem->getData('price') != '') {

        $quoteItem->setCustomPrice($orderItem->getData('price'));
        $quoteItem->setOriginalCustomPrice($orderItem->getData('price'));
    }

    return $this;
}

You can check Magento Core module - Mage_GiftMessage

So, when will edit Order via Adminpanel - prices will same. but be carefull with low prices :)

Adding to Magefast's solution, I've found that you also need to setCustomPrice() on the parent item when working with Configurable products. The quote will contain both the simple + configurable product, you want to make sure both rows get updated with the custom price.

Observer Method:

public function setCustomPriceForItem($observer)
{
    $quoteItem = $observer->getQuoteItem();
    $orderItem = $observer->getOrderItem();

    $session = Mage::getSingleton('customer/session');

    if ($session != null && !$session->getReordered() && $orderItem->getOriginalPrice() != $orderItem->getPrice()) {            
        $quoteItem->setCustomPrice($orderItem->getPrice());
        $quoteItem->setOriginalCustomPrice($orderItem->getPrice());

        //also update the price on the parent item
        if ($parentQuoteItem = $quoteItem->getParentItem()) {                  
            $parentQuoteItem->setCustomPrice($orderItem->getPrice());
            $parentQuoteItem->setOriginalCustomPrice($orderItem->getPrice());
        }
    }

    return $this;
}

Also see https://magento.stackexchange.com/questions/62422/getting-quote-cart-items-programatically-shows-duplicate-skus-for-both-the-con