Magento CE 1.4 Indexer - Index Management

I'm trying to create my own Indexer running Index in the Magento 1.4 community, the main goal of this custom indexer is to update the custom product attribute based on a set of calculations.

I looked into the main magento code and I did something similar to what I needed, but I could not find enough documentation on this.

this is 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 element in the index control grid, but when I ran the reindex action, it just ran the reindexAll () method.

Any ideas would be helpful and appreciated in advance.

+4
source share
1 answer

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

After saving the product, reindex is launched 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 look inside the processEntityAction, you will see that if your index is consistent and if the index mode is not β€œmanual”, then magento starts the _processEvent method of your indexer model. When Magento shuts down, it removes the pending entry from the index_process_event table.

When reindex starts from the admin panel, Magento checks to see if there are pending entries for your index in the "index_process_event" table, if so, Magento starts the _processEvent method of your model, otherwise it starts reindexAll. Thus, in your case, it is perfectly true that magento launches reindexAll. If you want Magento to run _processEvent instead of reindexAll, you must change your index mode to "Manual" through the admin panel.

+2
source

Source: https://habr.com/ru/post/1393841/


All Articles