I'm trying to do this for a while, but there's something isn't right about this, I've tried to put it in stock and enable it but nothing is working for me, can someone give me a hint or pinpoint me to the issue?

<?xml version="1.0"?>


And here's the observer:

class Mr_StockEnhancements_Model_Observer {

public function stockEnhancements(Varien_Event_Observer $observer) {

        $product   = $observer->getProduct();
        $stockData = $product->getStockData();

        //make sure stock qty is greater than zero.
        if (isset($stockData['qty']) && $stockData['qty'] >= 1) {

            $product->setStockData['is_in_stock'] = 1; //update to instock
            ->updateAttributes(array($product->getId()), array('status' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED), $storeId);

            print_r($stockData['qty'], $product->StockData['is_in_stock']);

        } else {
            Mage::getModel('catalog/product_status')->updateProductStatus($product->getProductId(), $storeId, Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
  • Is your observer working? – Vivek Kumar Aug 30 '18 at 19:15
  • Yes, it's working, but it isn't doing what it should be doing. – James Smith Aug 30 '18 at 21:14
  • Do you get desired data while printing? – Vivek Kumar Aug 30 '18 at 22:29
  • Yes, but it isn't updating as it should be, that's the only problem. – James Smith Aug 30 '18 at 23:52
  • Have you updated the event? – Vivek Kumar Aug 31 '18 at 0:17

You should use this observer on catalog_product_save_after event , replace your <catalog_product_prepare_save> tags in your xml to <catalog_product_save_after>


I think you've forgot to call $product->save() , so you should add it in the end of the code before print_r


Also your stock update code doesn't seem right .. Use following code ;

$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->setData('is_in_stock', 1);
$stockItem->setData('qty', 1);
  • I tried this, but still, it isn't working, the observer is working, but it seems like the function isn't working properly! what could I be missing here? – James Smith Aug 30 '18 at 22:24

Try this code.

    $productData = $observer->getProduct();
    $product = Mage::getModel('catalog/product')->load($productData->getId());
    $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
    $stockQty = $stock->getQty();

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.