Magento的自定义活动 [英] Custom Events in Magento
问题描述
如何在Magento中添加一个自定义事件,如done_some_thing?
How can I add a custom event in Magento like "done_some_thing"?
我正在编码一个购物车,给予客户一定的折扣优惠通过一个特定的链接,并希望在Cart和Checkout页面中显示相同的信息。
I am coding for a shopping cart which gives a certain % discount for the customers who comes through a particular link, and want to show the same in both Cart and Checkout Page
推荐答案
要发送事件,请使用 Mage :: dispatchEvent
function(%magento%/ app / Mage.php about line 425
)。电话看起来像这样:
To dispatch an event, use the Mage::dispatchEvent
function (%magento%/app/Mage.php around line 425
). Calls look like this:
$data = array( 'somedata' => 'foo', 'layout' => $this->getLayout());
Mage::dispatchEvent('my_event_name', $data);
为了观察事件,请在扩展名的config.xml文件中指定观察者。 / p>
In order to observe an event, specify the observer in the config.xml file of your extension.
<config>
<global>
<events>
<my_event_name>
<observers>
<myextension>
<type>singleton</type>
<class>myextension/observer</class>
<method>someMethodName</method>
</myextension>
</observers>
</my_event_name>
</events>
</global>
</config>
创建一个相应的类和方法(Observer.php),并设置为:
Create a corresponding class and method (Observer.php) and you're set to go:
class Myextension_Model_Observer {
public function someMethodName($event) {
$layout = $event->getLayout();
$someData = $event->getSomedata();
}
}
这篇关于Magento的自定义活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!