我正在尝试更新Magento中 sales_flat_order_item 表中的 additional_data 字段。
为此,我创建了一个自定义模块
这是我在app / code / local / Distelsa / Wedding / Models下的Observer.php:
class Distelsa_Wedding_Model_Observer{
public function AddWeddingIdToProduct(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$item = $event->getQuoteItem();
$quote = $item->getQuote();
$product = $observer->getEvent()->getProduct();
$controllerAction = $event->getControllerAction();
$params = $controllerAction->getRequest()->getParams();
$boda = Mage::app()->getRequest()->getParam('boda');
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$query = "UPDATE `sales_flat_quote_item` SET additional_data = '".$params['boda']."' where item_id = ".$item->getId();
$write->query($query);
}
}
这是我的config.xml:
<global>
<events>
<sales_order_save_after>
<observers>
<sales_order_save_after_wedding>
<type>model</type>
<class>wedding/observer</class>
<method>AddWeddingIdToProduct</method>
</sales_order_save_after_wedding>
</observers>
</sales_order_save_after>
</events>
</global>
有关如何使其有效的任何线索?
答案 0 :(得分:0)
<class>
文件中的config.xml
错误。
config.xml中的正确类如下所示:
<global>
<events>
<sales_order_save_after>
<observers>
<sales_order_save_after_wedding>
<type>model</type>
<class>distelsa_wedding/observer</class>
<method>AddWeddingIdToProduct</method>
</sales_order_save_after_wedding>
</observers>
</sales_order_save_after>
</events>
</global>
完成后清除chache。希望这可以帮助。