I am trying to follow the answer of this question Avoiding memory exhaustion when updating product stock? to rewrite a resource model. I created a custom module and is activated in the back-office. Here is my config.xml:

<?xml version="1.0" encoding="UTF-8"?>





When i do this :

$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->setData('is_in_stock', $quantity > 0 ? 1 : 0)->setQty($quantity);

Directories structure : app/code/local/Mymodule/Vendor/: -Model/CatalogInventory/Resource/Stock : item.php -etc : config.xml

I get this error : Fatal error: Call to undefined method Mage_CatalogInventory_Model_Resource_Stock_Item::saveAttribute()

I solved the error but i got another one:

Fatal error: Call to a member function loadByProduct() on a non-object

when i try this :

     $quantity = 8;
     $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
     $productId = $product->getId();
     $product = Mage::getModel('catalog/product')->load($productId);
     $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->setData('is_in_stock', $quantity > 0 ? 1 : 0)->setQty($quantity);

I didn't one to create another question so i edited this one.

2 Answers 2


The directory structure you have above is incorrect for the models.


CatalogInventory and Model were inverted in yours.

Magento can't find this in local so is trying to load Mage/CatalogInventory/... rather than Vendor/CatalogInventory.

Adding the Firegento Debugger plugin certainly helps to identify this sort of issue when creating new modules.

  • Your answer solved the loading of the method. I edited the question with another issue.
    – mockingbid
    Commented Aug 26, 2016 at 10:30
  • Might be better to add this as a second question. try removing $productId = $product->getId(); $product = Mage::getModel('catalog/product')->load($productId); as you already have the $product from the previous line
    – RichieJP81
    Commented Aug 26, 2016 at 11:10

As its a rewrite and you're defining new resource models you should simply remove the entire <resourceModel> node.

  • I removed the node but i still have the error.
    – mockingbid
    Commented Aug 25, 2016 at 17:29
  • This wouldn't be related to the problem I wouldn't imagine, although it's true
    – scrowler
    Commented Aug 25, 2016 at 17:58

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.