gpt4 book ai didi

Magento CE 1.4 索引器 - 索引管理

转载 作者:行者123 更新时间:2023-12-02 17:02:27 25 4
gpt4 key购买 nike

我正在尝试在 Magento 社区版 1.4 的索引管理下创建一个自定义索引器,该自定义索引器的主要目的是根据一组计算更新自定义产品属性。

我研究了 magento 核心代码,做了一些与我需要的类似的东西,但我找不到足够的围绕该主题的文档。

这是我到目前为止得到的:

配置.xml

<?xml version="1.0"?>
<config>
<!-- configuration -->
<global>
<index>
<indexer>
<custom_product_price>
<model>custom/indexer_price</model>
</custom_product_price>
</indexer>
</index>
</global>
<!-- configuration -->
</config>

然后我创建了一个模型

class MyModule_Custom_Model_Indexer_Price extends Mage_Index_Model_Indexer_Abstract
{
protected $_matchedEntities = array(
Mage_Catalog_Model_Product::ENTITY => array(
Mage_Index_Model_Event::TYPE_SAVE,
Mage_Index_Model_Event::TYPE_DELETE,
Mage_Index_Model_Event::TYPE_MASS_ACTION
)
);

/**
* Initialize resource model
*
*/
protected function _construct()
{
$this->_init('custome/indexer_price');
}

public function getName()
{
return Mage::helper('customizer')->__('Customizable Products');
}

public function getDescription()
{
return Mage::helper('customizer')->__('Index Customizable Product Prices');
}

public function matchEvent(Mage_Index_Model_Event $event) {
Mage::log("Should I match an event: ".$event->getEntity() . '|'. $event->getType());
return true;
}

protected function _registerEvent(Mage_Index_Model_Event $event) {
Mage::log("Should I register an event: ".$event->getEntity() . '|'. $event->getType());
}

protected function _processEvent(Mage_Index_Model_Event $event) {
Mage::log("Should I process an event: ".$event->getEntity() . '|'. $event->getType());
}

public function reindexAll() {

Mage::log('Do my processing to reindex');
}
}

实现此代码后,我能够在索引管理网格下看到新的自定义索引器项目,但是当我运行重新索引操作时,它只是触发了 reindexAll() 方法。

任何想法都会有所帮助,并提前致谢。

最佳答案

这是正确的 Magento 行为。这是一个解释:(代码示例取自magento ce 1.4.0.0)

产品保存后,在以下调用中的 Mage_Catalog_Model_Product::afterCommitCallback() 中触发重新索引:

Mage::getSingleton('index/indexer')->processEntityAction($this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE);

如果您查看 processEntityAction 内部,您将看到,如果您的索引匹配并且索引模式不是“手动”,则 magento 会运行​​索引器模型的 _processEvent 方法。当 Magento 完成运行时,它会从“index_process_event”表中删除待处理的条目。

当您从管理面板运行重新索引时,Magento 会检查“index_process_event”表中是否有索引的挂起条目,如果有 - Magento 运行_processEvent 模型的方法,否则它将运行 reindexAll。因此,就您而言,magento 运行 reindexAll 是完全正确的。如果您希望 Magento 运行 _processEvent 而不是 reindexAll,您应该通过管理面板将索引模式更改为“手动”。

关于Magento CE 1.4 索引器 - 索引管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9069556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com