Events Magento v1.7中的事件代码不工作
一整天 我正在尝试编写我的第一个magento事件处理程序,以在之后捕获checkout\u cart\u save\u,但我无法启动我的Observer.php代码,在查看有关magento事件的网站2天后,我了解了整个过程,但代码没有运行。。我不明白为什么 下面是/var/magento/app/etc/modules中的模块xml文件/Events Magento v1.7中的事件代码不工作,events,magento,Events,Magento,一整天 我正在尝试编写我的第一个magento事件处理程序,以在之后捕获checkout\u cart\u save\u,但我无法启动我的Observer.php代码,在查看有关magento事件的网站2天后,我了解了整个过程,但代码没有运行。。我不明白为什么 下面是/var/magento/app/etc/modules中的模块xml文件/ <?xml version="1.0"?> <config> <modules> <Namespac
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Yourmodule>
<codePool>local</codePool>
<active>true</active>
<version>1.0.0</version>
</Namespace_Yourmodule>
</modules>
</config>
尝试从购物车中添加和删除项目的结果是,不会创建任何日志文件,手动创建时,不会写入任何数据,system.log不会显示任何错误,如果我扭曲XML,它会报告错误,因此正在读取XML文件
有没有想过我错过了什么
希德
更新12/2:
我已经花了一个周末的时间解决了这个问题,感谢您的提示,这是我应该学习的一些小东西的组合,现在XML文件的格式与上面建议的格式相匹配。。。现在有一个教程!我已经用工作代码和配置文件完整地记录了这个过程
请参见尝试将config.xml更新为
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Yourmodule>
<version>1.0</version>
</Namespace_Yourmodule>
</modules>
<global>
<!--helpers>
<yourmodule>
<class>Namespace_Yourmodule_Helper</class>
</yourmodule>
</helpers-->
<models>
<yourmodule>
<class>Namespace_Yourmodule_Model</class>
</yourmodule>
</models>
<events>
<checkout_cart_save_after>
<observers>
<yourmodule_after_observer>
<type>singleton</type>
<class>Namespace_Yourmodule_Model_Observer</class>
<method>checkout_cart_save_after</method>
</yourmodule_after_observer>
</observers>
</checkout_cart_save_after>
</events>
</global>
</config>
请参见我模块的etc目录/var/magento/app/code/local/Namespace/Yourmodule/module中的/var/magento/app/code/local/Namespace/Yourmodule/**etc**!!!!我已经花了一个周末的时间解决了这个问题,感谢您的提示,这是我应该学习的一些小东西的组合,现在XML文件的格式与上面建议的格式相匹配。。。现在有一个教程!我已经用工作代码和配置文件完整地记录了这个过程。
class Namespace_Yourmodule_Model_Observer
{
/*----------------------------------------
*
* LogInfo()
*
* Basic logging of activity to disk for debugging
*/
public function LogInfo($msg)
{
$logfile="/logs/Namespace-module.log";
$fd=fopen($logfile,"a");
if($fd)
{
fwrite($fd,$msg."\n");
fclose($fd);
}
}
public function checkout_cart_save_before($observer)
{
LogInfo("save_before called");
}
public function checkout_cart_save_after($observer)
{
LogInfo("save_after called");
}
}
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Yourmodule>
<version>1.0</version>
</Namespace_Yourmodule>
</modules>
<global>
<!--helpers>
<yourmodule>
<class>Namespace_Yourmodule_Helper</class>
</yourmodule>
</helpers-->
<models>
<yourmodule>
<class>Namespace_Yourmodule_Model</class>
</yourmodule>
</models>
<events>
<checkout_cart_save_after>
<observers>
<yourmodule_after_observer>
<type>singleton</type>
<class>Namespace_Yourmodule_Model_Observer</class>
<method>checkout_cart_save_after</method>
</yourmodule_after_observer>
</observers>
</checkout_cart_save_after>
</events>
</global>
</config>