我的 Alchemy 目录模块中有这个 XML 结构:
<?xml version="1.0" encoding="UTF-8"?>
<!--
@filepath /app/code/local/Alchemy/Catalog/etc
The XML has been extended following
Magento Events API Observers
http://www.excellencemagentoblog.com/magento-part11-series-eventsapi
or
http://blog.chapagain.com.np/magento-event-observer-with-save-before-and-save-after/
-->
<config>
<modules>
<Alchemy_Catalog>
<version>0.1.0</version>
</Alchemy_Catalog>
</modules>
<global>
<models>
<alchemycatalog>
<rewrite>
<product>Alchemy_Catalog_Model_Product</product>
<block>Alchemy_Catalog_Model_Block</block>
</rewrite>
</alchemycatalog>
</models>
<events>
<!--
Examples: catalog_product_save_before, catalog_product_prepare_save
Check out Magento events cheat sheet at http://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/ -->
<catalog_product_save_after>
<observers>
<Alchemy_Catalog>
<type>singleton</type>
<class>Alchemy_Catalog_Model_Product</class>
<method>pingBaseProductService</method>
</Alchemy_Catalog>
</observers>
</catalog_product_save_after>
<catalog_category_save_after>
<observers>
<Alchemy_Catalog>
<type>singleton</type>
<class>Alchemy_Catalog_Model_Product</class>
<method>pingBaseCategoryService</method>
</Alchemy_Catalog>
</observers>
</catalog_category_save_after>
<cms_block_save_before>
<observers>
<Alchemy_Catalog>
<type>singleton</type>
<class>Alchemy_Catalog_Model_Block</class>
<method>rabbitmqBlockProducer</method>
</Alchemy_Catalog>
</observers>
</cms_block_save_before>
</events>
</global>
</config>
这个模型应该记录一条消息来证明它有效:
<?php
class Alchemy_Catalog_Model_Block extends Mage_Cms_Model_Block {
/**
* Implement function rabbitmqBlockProducer().
* This function writes a message to the rabbit
* mq server
*/
protected $_eventPrefix = 'cms_block';
public function rabbitmqBlockProducer ($event) {
Mage::log('save3 block invoked', null, 'marian.log');
}
/**
* Prevent blocks recursion
*
* @throws Mage_Core_Exception
* @return Mage_Core_Model_Abstract
*/
protected function _beforeSave() {
Mage::log('save2 block invoked', null, 'marian.log');
}
}
但是rabbitmqBlockProducer()方法永远不会被调用。注意:产品和目录的其他方法工作得很好。
任何解决此问题或任何其他方法的帮助将不胜感激