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.


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 Aug 26 '16 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 – Weaves81 Aug 26 '16 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 Aug 25 '16 at 17:29
  • This wouldn't be related to the problem I wouldn't imagine, although it's true – Robbie Averill Aug 25 '16 at 17:58

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.