I'm attempting to use multiple observer classes & modules for Magento, all of which are being put into app/code/local. These all work on my local workstation, but will NOT work when I copy them to production via FTP. I am going crazy trying to figure out what's going on. All of my code seems sound. Here's an example of an observer:
app/code/local/Mural/Pricing/Model/Observer.php
<?php
class Mural_Pricing_Model_Observer {
public function setMuralPricing($observer) {
echo 'We did it!';
die();
}
}
app/code/local/Mural/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Mural_Pricing>
<version>0.0.1</version>
</Mural_Pricing>
</modules>
<global>
<models>
<Mural_Pricing>
<class>Mural_Pricing_Model</class>
</Mural_Pricing>
</models>
</global>
<adminhtml>
<events>
<sales_quote_add_item>
<observers>
<Mural_Pricing>
<class>mural_pricing/observer</class>
<method>setMuralPricing</method>
</Mural_Pricing>
</observers>
</sales_quote_add_item>
</events>
</adminhtml>
</config>
app/etc/modules/Mural_Pricing.xml
<?xml version="1.0"?>
<config>
<modules>
<Mural_Pricing>
<codePool>local</codePool>
<active>true</active>
<depends>
<Mage_Catalog />
</depends>
</Mural_Pricing>
</modules>
</config>
Like I said, this works fine locally, but not in production, with several different observers & modules. Frustrating. Thank you in advance!
答案 0 :(得分:1)
我注意到的第一件事是你的观察者声明是在观察到的事件上调用mural_pricing/observer::setMuralPricing()
。
如果查看配置XML,您可以按照此XML将此模块中的模型注册为Mural_Pricing/...
:
<models>
<Mural_Pricing>
<class>Mural_Pricing_Model</class>
</Mural_Pricing>
</models>
Magento最佳实践似乎是对类别名使用全小写,因此我建议您将其更改为mural_pricing
。如果您将观察者声明更改为使用大写的等效声明,它也会起作用。
另一方面,我并不认为您为此标记命名的内容确实很重要,但<Mural_Pricing>
下面的<observers>
标记应理想地代表观察者所做的简短描述(再次,不要认为实际上很重要 - 例如<mural_pricing_set_pricing>
。
最后,必须说明 - 确保您已正确清除缓存以重新解析XML配置。如果您在生产中使用Redis或其他缓存架构vs dev / staging / local,那么您可能忘记以不同的方式清除缓存,而不是在本地执行操作。
最终,除了类别名和观察者声明中的大小写差异之外,您的模块看起来很好。