0

Ok so i got an answer to my question about AUTO turning on the Stock Availability status to 'In Stock' (from 'Out of Stock') after we increase quantity from 0. The answer was to try this module below,but its not working for me.could you please tell if i am placing the files right way?

  • My Module Namespace : Apollo

  • Module Name: Proaval

I have set all these directories:

  • App/Code/Local/Apollo/Proaval/Block
  • App/Code/Local/Apollo/Proaval/controllers
  • App/Code/Local/Apollo/Proaval/etc
  • App/Code/Local/Apollo/Proaval/Helper
  • App/Code/Local/Apollo/Proaval/Model
  • App/Code/Local/Apollo/Proaval/sql

My Apollo_Proaval.xml is in App/etc/modules, which has the following code:

    <?xml version="1.0" ?>
    <config>
<modules>
    <Apollo_Proaval>
       <active>true</active>
       <codePool>local</codePool>
    </Apollo_Proaval>
</modules>
    </config>

Next, please check my config.xml in app/code/local/Apollo/Proaval/etc/config.xml

    <?xml version="1.0"?>
    <config>
<global>
     <events>
    <catalog_product_save_after>
            <observers>
                <Save_product_data>
                    <type>singleton</type>
                    <class>Magetest_test_Model_Observer</class>
                    <method>changeStockStatus</method>
                </Save_product_data>
            </observers>
    </catalog_product_save_after>
</events>
      </global>
    </config>

And finally here is the Oberver.php located in app/code/local/Apollo/Proaval/Observer.php

    <?php 
    public function changeStockStatus($observer) {
        $product = $observer->getProduct();
        $stockData = $product->getStockData();

        if ( $product && $stockData['qty'] > 0) {
            $stock =   Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getEntityId()); // Load the stock for this product
    $stock->setData('is_in_stock', 1); // Set the Product to InStock                               
    $stock->save(); // Save
}
    }

What i am suspecting is there is perhaps something wrong with config.xml?Please check it once.

1

There are several issues with your files. First, I have corrected your config.xml file:

<?xml version="1.0"?>
<config>
    <modules>
        <Apollo_Proaval>
            <version>0.1.0</version>
        </Apollo_Proaval>
    </modules>
    <global>
        <events>
            <catalog_product_save_after>
                <observers>
                    <save_product_data>
                        <type>singleton</type>
                        <class>Apollo_Proaval_Model_Observer</class>
                        <method>changeStockStatus</method>
                    </save_product_data>
                </observers>
            </catalog_product_save_after>
        </events>
    </global>
</config>

Please note that

  • I added a <modules> node with module name and version information
  • I renamed the class in the observer from Magetest_test_Model_Observer to Apollo_Proaval_Model_Observer

Also, your observer needs to be a class file - Magento is full OOP. You can see that you must provide a class in the config.xml file, so, where is this class? ;)

<?php
class Apollo_Proaval_Model_Observer {

    public function changeStockStatus($observer) {
        $product = $observer->getProduct();
        $stockData = $product->getStockData();

        if ( $product && $stockData['qty'] > 0) {
            // load stock item
            $stock =   Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());         
            $stock->setData('is_in_stock', 1); // Set the Product to InStock                               
            $stock->save(); // Save
        }
        return $this;
    }
}

Note that

  • I wrapped the function inside a class named Apollo_Proaval_Model_Observer, just like in the config.xml
  • I changed $product->getEntityId() to $product->getId() - yours would have worked to, but getId() is convention
  • I made the method return $this, which is a mere personal preference I guess

What's more

From your question and your errors, I assume that you may have worked with PHP, but are not specifically experienced with Magento. You should have a look at the official Extension Developer's Guide for information about the structure of the whole system and its modules.

Also, when you look into the index.php file in your Magento directory, you will see a line Mage::setIsDeveloperMode(true);. Enabling this developer mode by setting the environment variable in your webserver configuration or simply commenting the if-statement around it provides more error details.

Last but not least, be sure to enable logging in the admin area.

  • You are the real magento champ. you made my day.live long,stay blessed :) sorcerer in true terms you are – tallal hassan Jul 29 '15 at 22:55
  • Lol no problem :) – simonthesorcerer Jul 29 '15 at 22:57

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.