我正在尝试扩展Magento中的客户模块,但我没有太多的运气。
我有:将MyModule_Customer.xml添加到etc/modules目录,并设置正确的名称和路径。创建了MyModule/Customer/etc/config.xml创建了一个MyModule/Customer/Model/Customer.php(从Core/Customer复制)。我添加了一个Mage::log到我的新类,但它从来没有记录任何东西。
有很多事情我不确定。我的Customer.php类声明是否扩展了Mage_Customer_Model_Customer类或Mage_Core_Model_Abstract类?我在网上看到的不一致。
这是MyModule/etc/config.xml中重写部分的正确格式吗?MyModule_Customer_Model_Customer…还是里面应该有另一个元素?我试着在路径周围添加,但这使Magento完全停止工作。
编辑:当地/MyModule里/客户/etc/config . xml这实际上是Mage/Customer config.xml的副本,其中重新定义了模块,并添加了重写部分
<pre>
global>
models>
customer>
rewrite>
customer>
MyModule_Customer_Model_Customer
/customer>
/rewrite>
/customer>
/models>
/global>
</pre>
但是这导致Magento中断并且不显示任何内容。我目前最好的猜测是如上所述,但删除了大多数内部客户元素。
编辑2:这是所有的代码app/etc/模块/MyModule_Customer.xml<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyModule_Customer>
<active>true</active>
<codePool>local</codePool>
<depends>
Mage_Customer
</depends>
</MyModule_Customer>
</modules>
</config>
一个关于这个格式的查询-我看到的大多数文章都没有依赖元素,但我认为我应该尝试一下,这是有意义的。但这对吗?
My local/MyModule/Customer/Model/Customer.php声明:
class MyModule_Customer_Model_Customer extends Mage_Customer_Model_Customer
就是这些。我在网上读的教程建议这应该是微不足道的,所以我做错了什么?任何帮助都将非常感激。谢谢你。
我终于找到了解决办法。在扩展类中,使用require_once来引用核心类。例如require_once(法师/客户/模型/Customer.php);
您不应该将自己的模块命名为与原始模块相同,在本例中为'Customer'。它可以工作,但它非常令人困惑。对于Magento和其他可能在您的代码上工作的开发人员。
当覆盖Customer模型时,您将需要扩展Mage_Customer_Model_Customer。在这种情况下,您只需要将方法放在您想要重写的类中。不需要复制整个父类。
请添加完整的config.xml:)