【问题标题】:Magento CE 1.4 Indexer - Index ManagementMagento CE 1.4 索引器 - 索引管理
【发布时间】:2012-01-30 19:28:28
【问题描述】:

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

我查看了 magento 核心代码,并做了一些与我需要的类似的东西,但我找不到足够的关于该主题的文档。

这是我目前得到的:

config.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');
}
}

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

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

【问题讨论】:

  • 不确定您在这里实际问的是什么?

标签: magento indexing magento-1.4


【解决方案1】:

这是正确的 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,您应该通过管理面板将索引模式更改为“手动”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多