1

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

}
4

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
3

File: app/code/local/Namespace/Module/etc/config.xml

<config>
    . . . 
    <global>
       <models>
          <module>
                <class>Namespace_Module_Model</class>
          </module>
          <cataloginventory>
                <rewrite>
                    <stock_item>Namespace_Module_Model_Stock_Item</stock_item>
                </rewrite>
            </cataloginventory>
       </models>
    . . . 
    </global>
    . . . 
 </config>

File: app/code/local/Namespace/Module/Model/Stock/Item.php

<?php
class Namespace_Module_Model_Stock_Item extends Mage_CatalogInventory_Model_Stock_Item
{

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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