如果你想在某个核心功能增加功能,那magento的event机制就可以大显神威了。
magento通过下面两个方法分发和捕捉事件
Magento中你需要调用 Mage::dispatchEvent(…) 就可以分发(Dispatch)一个Event, 例系统用户登陆事件:
Mage::dispatchEvent('customer_login', array('customer'=>$customer));
分发之后你需要捕捉事件(Catching events)在配置文件confi.xml
<frontend> <events> <customer_login> <observers> <catalog> <type>model</type> <class>catalog/product_compare_item</class> <method>bindCustomerLogin</method> </catalog> </observers> </customer_login> </events> </frontend>
那么当用户登陆,就会调用catalog_model_product_compare_item下面的方法bindCustomerLogin
这样你就可以对用户登陆绑定事件,做出相应的处理
下面是通过shell脚本例出所有magento的事件:
#!/bin/bash # Find all Magento Events, include file names, line numbers and the preceding 6 lines of code #Please define these two ABSOLUTE_PATH_TO_MAGENTO_ROOT=/home/project/magento/ #here is the command find $ABSOLUTE_PATH_TO_MAGENTO_ROOT -name "*.php" | xargs -L10 grep -n -B 6 "dispatchEvent" . > "/home/project/magento/magentoEvents.txt"
保存上面命令为 magentoevents.sh 脚本
改变权限为可执行: chmod +x magentoevents.sh
通过shell运行脚本: ./magentoevents.sh