注文のステータスが完了に変更されたときに在庫をエクスポートするイベントを作成したいと考えています。
Mage_Sales_Model_Orderを上書きするモジュールを作成し、イベントを生成してみました
(sales_order_status_change)。
Magento管理パネルから表示して注文し、注文状態を完了に変更すると、拡張クラスで何かを印刷することを意味し、それはうまくいきます。ここでイベントを生成します(問題はここにある可能性があり、イベントが生成されない可能性があります)
このイベントを監視するために別のモジュールを作成しました。しかし、Observer クラスに入ることができません。何も印刷して終了できません。コードが実行されないことを意味します。
ただし、構成を変更して他のイベント(Magento組み込みイベントから)を観察すると、同じオブザーバークラスで機能します。私がcatalog_controller_product_viewをテストしたように
これが私のイベントジェネレータモジュールです。
app/etc/modules/Gol_Eventgenerator.xml
<?xml version="1.0"?>
<config>
<modules>
<Gol_Eventgenerator>
<active>true</active>
<codePool>local</codePool>
</Gol_Eventgenerator>
</modules>
</config>
app\code\local\Gol\Eventgenerator\etc\config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Gol_Eventgenerator>
<version>0.1.0</version>
</Gol_Eventgenerator>
</modules>
<global>
<models>
<sales>
<rewrite>
<order>Gol_Eventgenerator_Model_Order</order>
</rewrite>
</sales>
</models>
</global>
</config>
app\code\local\Gol\Eventgenerator\Model\Order.php
<?php
class Gol_Eventgenerator_Model_Order extends Mage_Sales_Model_Order
{
public function setState($state, $status = false, $comment = '', $isCustomerNotified = null)
{
//if I print something here and exit, it does will.
Mage::dispatchEvent('sales_order_status_change', array('order' => $this, 'state' => $state, 'status' => $status, 'comment' => $comment, 'isCustomerNotified' => $isCustomerNotified));
return parent::setState($state, $status, $comment, $isCustomerNotified);
}
}
オブザーバーモジュールの詳細はこちら
app/etc/modules/Gol_Inventory.xml
<?xml version="1.0"?>
<config>
<modules>
<Gol_Inventory>
<active>true</active>
<codePool>local</codePool>
</Gol_Inventory>
</modules>
</config>
app\code\local\Gol\Inventory\etc\config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Gol_Inventory>
<version>0.1.0</version>
</Gol_Inventory>
</modules>
<global>
<events>
<sales_order_status_change>
<observers>
<Gol_Inventory_observer>
<type>singleton</type>
<class>Gol_Inventory_Model_Observer</class>
<method>exportEnventory</method>
</Gol_Inventory_observer>
</observers>
</sales_order_status_change>
</events>
</global>
</config>
app\code\local\Gol\Inventory\Model\Observer.php
<?php
class Gol_Inventory_Model_Observer
{
public function exportEnventory($observer)
{
echo "Inside exportEvnentory method";
exit;
//$order = $observer->getEvent()->getOrder();
//$state = $observer->getEvent()->getState();
//$status = $observer->getEvent()->getStatus();
}
}
フロントエンドと管理者のイベントを生成する方法に違いはありますか??? を除外する
、構成ファイル内。
非常に一般的なことに従っていない場合は、事前に申し訳ありません。マジェントの新機能。
フォローしてみました。