6

I have a situation where I'd like to completely disable one of Magento's core indexers (cataloginventory_stock). I don't want this index to ever be rebuilt, maintained or altered in any way.

Is it possible to disable or "unregister" an indexer?

Things I've tried:

  1. See if there's a way to disable it via config xml (there isn't).
  2. Look for events around config xml loading that might permit me to remove the indexer's definition in XML before it can be used. There isn't, and that's logical as until the XML is loaded there's no way to define event observers!

What does seem to work is to rewrite the Mage_CatalogInventory_Model_Indexer_Stock class and replace most of it's methods with versions that either return false (matchEvent and matchEntityAndType) or are otherwise NoOps. While this works, it doesn't seem like a particularly elegant solution. Is there a better way?

Please Note: I am aware that there will be many flow on effects from disabling this particular indexer, and I've dealt with most of them already.

2
  • Is there any reason that disabling inventory management in the admin wouldn't be equally suitable? Commented Oct 14, 2014 at 8:10
  • I still need Magento to be aware of inventory and decrement inventory on order place, etc but the inventory levels (and consequently stock status flags and is saleable) will be stored outside of Magento (and will change without triggering Magento events). I don't want Magento to maintain the stock status index given that we will never use it. If we can achieve that by disabling inventory management in the admin, please post an answer with some details, I'd love to know more! Commented Oct 14, 2014 at 23:58

3 Answers 3

8

I was struggling with the same issue, and got a clean solution to it.

Mage_Index_Model_Indexer_Abstract has an inbuilt function called isVisible()

If this function returns false, then the indexer is disabled completely.

So you can extend class Mage_CatalogInventory_Model_Indexer_Stock and then add isVisible() function to it which returns false (hardcode / by a config entry for enable/disable), which will hide / disable the indexer.

You can also refer Mage_Catalog_Model_Category_Indexer_Flat, this indexer uses the same concept.

Hope this solutions helps someone

2
  • 2
    This ansewer is the most accurate and clean. it saved me a lot of time with a simple rewrite. Commented Oct 7, 2016 at 12:02
  • Making the indexer not visible does not disable it! If I import products it still reindexes afterwards. Commented Dec 19, 2018 at 14:36
3

You are right. It does not seam to be a way to disable it via config.xml.
The only option seams to be the overriding the stock index model.
If this seams like an ugly way of doing it, there could be an other way.
It's almost the same thing as rewriting the class but not quite.
You can create your own model and replace the original model.
This means that your class will be called instead of the original one (but you don't rewrite the original class).

You will need to add this in the config.xml of one of your custom modules.

<global>
    ....
    <index>
        <indexer>
            <cataloginventory_stock>
                <model>[module]/indexer_stock</model>
            </cataloginventory_stock>
        </indexer>
    </index>
    ....
</global>

Then just create the class

class Namespace_Module_Model_Indexer_Stock extends Mage_Index_Model_Indexer_Abstract {
   //implement abstract methods from the Mage_Index_Model_Indexer_Abstract  class and make them return dummy things.
}

It's kind of the same thing, but it looks a bit cleaner.

2

What you can do is set

/config/global/index/indexer/catalog_product_attribute/model

which is catalog/product_indexer_eav at the moment to <model />.

(of course you can do this with every other indexer)

But I have no idea what the side effect is. At least, the indexer shouldn't run anymore (and I think it is not shown in the backend too)

Or you can do it as magento, the way you already did it, just exchange the Indexer model with a dummy. Magento does this in Enterprise 1.14 after the partitial indexing was introduced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.