[英]What is the correct way to stop a checkout from an event observer in Magento?
[英]What is the correct way to set up an observer in Magento?
我想在Magento中設立一個觀察員,在訂單狀態發生變化時執行操作。
我熟悉創建模塊的過程。 我想要了解的是需要在模塊config.xml中放置什么,以及需要創建的類和/或方法的命名約定是什么。
我沒有在任何地方看到事件名稱,但我會在這里發布一般情況:
假設:您已經設置了一個模塊,模型正在從Yourmodule / Model目錄中正確加載。
在模塊的config.xml文件中:
<config>
<global>
<events>
<full_event_name>
<observers>
<yourmodule>
<type>singleton</type>
<class>yourmodule/observer</class>
<method>yourMethodName</method>
</yourmodule>
</observers>
</full_event_name>
</events>
</global>
</config>
使用以下內容創建文件%yourmodule%/ Model / Observer.php:
<?php
class Yourmodule_Model_Observer {
public function yourMethodName($event) {
$data = $event->getData(); // this follows normal Magento data access
// perform your action here
}
}//class Yourmodule_Model_Observer
實際上,您可以在觀察者中以任何方式命名方法,但模式似乎是將類命名為Observer。 它使用正常模型加載加載(例如,yourmodule / observer映射到Yourmodule_Model_Observer)。 希望有所幫助!
謝謝,喬
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.