2012-03-05 75 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

相关问题