I'm trying to create a custom indexer for a particular product attribute.
I need to:
- read the product attribute value
- process it in some way ( not relevant )
- save it in a index table
The above steps could be implemented in a custom script but I would like integrate the indexer using the patter used by other indexer in Magento.
I can see that Magento default indexer implement this abstract class Mage_Index_Model_Indexer_Abstract
… It looks not easy to understand the process from the code and I cannot find any documentation for it.
Any help is appreciate thanks.
Best Answer
Following info should be a generic guide line that lead to a basic understanding of the whole
indexer thing
, so are not a complete 'walkthrough' ... ( if you want to contribute to this answer you are welcome )There are at least 3 steps required here:
Mage_Index_Model_Indexer_Abstract
Suggested documentation:
Mage_Catalog_Model_Product_Indexer_Price
( this is one of the easier index implementation ).STEP 1
Just add your index table in the installer, as for any other module table.
Your resource model needs to implement the logic for
Reindex All
in thereindexAll()
method: you would probably process all entities here an extract all data.STEP 2
_registerEvent()
,_processEvent()
are the important method here, you will need to dig a bit in the below guide to understand the logic behind themBasically
_registerEvent()
add some data to the$event
, on the base of the 'event type' and the 'entity type'. This extra data will be used in_processEvent()
method.You will need to implement at least the following methods in your model.
STEP 3
Add this to your configuration, [module/model] is the model created in step 2. So at this point if you go in system->indexer you will see a new entry
Sources: