Indexador Magento CE 1.4 - Gestión de índices

I'm trying to create a custom Indexer under Index Management in Magento community edition 1.4, the main purpose of this custom indexer is to update a custom product attribute based on a set of calculations.

I looked into magento core code and I made something similar to what I need, but I couldn't find enough documentations around the subject.

this what I got so far:

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>

Then I created a model

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

after implementing this code I was able to see my new custom indexer item under Index Management grid, but when I ran reindex action it just fired reindexAll() method.

Any ideas would be helpful and thank in advance.

preguntado el 30 de enero de 12 a las 19:01

Not sure what you are actually asking here? -

1 Respuestas

This is correct Magento behavior. Here is an explanation: (the code examples are taken from magento ce 1.4.0.0)

After product save, the reindex is triggered in Mage_Catalog_Model_Product::afterCommitCallback() in the following call:

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

If you will take a look inside processEntityAction, you will see that if your index is matched and if the index mode is not "manual", then magento runs the _processEvent method of your indexer model. When Magento finishes running it, it deletes the pending entry from the "index_process_event" table.

When you run the reindex from the admin panel, Magento checks whether there are pending entries for your index in "index_process_event" table, if yes - Magento runs the _processEvent method of your model, otherwise it runs the reindexAll. Thus, in your case, it is totally correct that magento runs the reindexAll. If you want that Magento will run the _processEvent instead of reindexAll, you should change your index mode to "Manual" through the admin panel.

Respondido 08 Feb 17, 19:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.