好的,我在网上搜索过,没有任何效果。结果非常不一致。让我先告诉你我在这里有什么。它最终将创建一个导出文件,但无法获取订单数据和对象。
class Packagename_Modulename_Model_Observer
{
public function exportFeed (Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$ordered_items = $order->getAllItems();
和config.xml
<global>
<events>
<sales_order_place_after>
<observers>
<packagename_modulename_order_observer>
<class>Packagename_Modulename_Model_Observer</class>
<method>exportFeed</method>
</packagename_modulename_order_observer>
</observers>
</sales_order_place_after>
</events>
</global>
现在,我看到人们在没有Varien_Event_Observer的情况下使用,
public function exportFeed ($observer)
我也试过没有getEvent()
$order = $observer->getOrder();
和config.xml中的不同之处,有和没有单例
<type>singleton</type>
<class>packagename_modulename/observer</class>
我想要做的就是导出通过Magento下订单时订购的特定商品的库存Feed。
答案 0 :(得分:4)
尝试
在config.xml中
<config>
<modules>
<Packagename_Modulename>
<version>1.3</version>
</Packagename_Modulename>
</modules>
....
<global>
<models>
<packagename_modulename>
<class>Packagename_Modulename_Model</class>
</packagename_modulename>
</models>
<events>
<sales_order_place_after>
<observers>
<packagename_modulename_order_observer>
<type>singleton</type>
<class>modulename/observer</class>
<method>exportFeed</method>
</packagename_modulename_order_observer>
</observers>
</sales_order_place_after>
在Observer.php中
class Packagename_Modulename_Model_Observer
{
public function exportFeed($event)
{
$order = $event->getOrder();
foreach ($order->getAllVisibleItems() as $item){
$item->getQtyOrdered() // Number of item ordered
//$item->getQtyShipped()
//$item->getQtyInvoiced()
$optionArray = $item->getProductOptions()
// Todo : check to see if set and is array $optionArray['options']
foreach($optionArray['options'] as $option){
// Mage::log($option)
//echo $option['label']
//$option['value']
}
}