2012-03-05 73 views
0

我有一些產品具有自定義價格。根據選擇的選項,有一個應用的公式可以爲產品增加費用,所以價格絕不相同。我的問題是,當你重新排序,重新排序的產品的價格始終爲0Magento:以自定義價格重新訂購商品,價格始終爲0

在銷售/控制器/ OrderController,在功能重新排序,有這樣的:

$order = Mage::registry('current_order'); 
$items = $order->getItemsCollection(); 
foreach ($items as $item) { 
    try { 
     $cart->addOrderItem($item); 
     ... 

如果我添加這些行,我能夠檢索自定義價格,但我找不到編輯該項目的方式,以便在重新排序中添加價格。

$options = $item->getProductOptions(); 
$options = $options['info_buyRequest']; 
$customPrice = $options['custom_price']; 

有什麼我都試過(中環,前$ cart-> addOrderItem($項目)),但沒有成功。

$item->setSpecialPrice($customPrice); 
$item->setCustomPrice($customPrice); 
$item->setOriginalPrice($customPrice); 
$item->setBaseOriginalPrice($customPrice); 
$item->setBaseCost($customPrice); 
$item->setBaseRowInvoiced($customPrice); 
$item->setRowInvoiced($customPrice); 
$item->save(); 

任何幫助?

回答

3

幾種可能性。我想爲checkout_cart_product_add_after事件嘗試一個事件觀察者。

// observer method: 
public function checkoutCartProductAddAfter(Varien_Event_Observer $observer) 
{ 
    $action = Mage::app()->getFrontController()->getAction(); 
    if ($action->getFullActionName() == 'sales_order_reorder') 
    { 
     $buyInfo = $observer->getQuoteItem()->getBuyRequest(); 
     if ($customPrice = $buyInfo->getCustomPrice()) 
     { 
      $observer->getQuoteItem()->setCustomPrice($customPrice) 
       ->setOriginalCustomPrice($customPrice); 
     } 
    } 
} 
+0

謝謝!我會試試這個,但是你的$物品是從哪裏來的? – 2012-03-05 16:30:04

+0

Ups,對不起,這將是'$ observer-> getQuoteItem()'。我更新了示例代碼。 – Vinai 2012-03-05 16:32:19

+2

是的,我在你的答案之前就已經明白了,它工作正常。非常感謝! – 2012-03-05 16:37:03

相關問題