Magento CE 1.7.0.2 – Model Override Not Working

ce-1.7.0.2

We try to override two functions from the Mage_CatalogInventory_Model_Stock_Item model class but unfortunately nothing happens. Maybe we missed something?

#File: app/code/local/Namespace/Module/etc/config.xml
<blocks>
    <models>
        <cataloginventory>
            <rewrite>
                <stock_item>Namespace_Module_Model_Stock_Item</stock_item>
            </rewrite>
        </cataloginventory>
    </models>
</blocks>

#File: app/code/local/Namespace/Module/Model/Stock/Item.php
<?php
class Namespace_Module_Model_Stock_Item extends Mage_Core_Model_Abstract
{   

    public function getMinSaleQty()
    {
        echo 'test';
        exit;
    }

    public function getQtyIncrements()
    {
        echo 'test';
        exit;       
    }

}

Best Answer

The code in the xml appears to be wrong, blocks and models should be separate and should be included as part of the global node. If you update your config as below:

#File: app/code/local/Namespace/Module/etc/config.xml
<global>
    <models>
        <cataloginventory>
            <rewrite>
                <stock_item>Namespace_Module_Model_Stock_Item</stock_item>
            </rewrite>
        </cataloginventory>
    </models>
</global>

You should also extend the rewritten class and not the abstract so your class should start

class Namespace_Module_Model_Stock_Item extends Mage_CatalogInventory_Model_Stock_Item
Related Topic