i am trying building a small module which house a Observer for getting called when and event called when catalog_product_import_profile_after is fired this is custom event which i have fired using the


in the app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php file

My module config.xml is

<?xml version="1.0"?>
      <catalog_product_import_profile_after> <!-- identifier of the event we want to catch -->
        <catalog_product_import_profile_after_handler> <!-- identifier of the event handler -->
        <type>model</type> <!-- class method call type; valid are model, object and singleton -->
        <class>clearorphan/observer</class> <!-- observers class alias -->
        <method>disableProducts</method>  <!-- observer's method to be called -->
        <args></args> <!-- additional arguments passed to observer -->

and the Observer.php is

class GWB_ClearOrphan_Model_Observer

        public function disableProducts(Varien_Event_Observer $observer)
            //mail('[email protected]','sub-test','msg-test');

                $collection = Mage::getModel('catalog/product')->getCollection();

                $pro_collection = var_dump($collection);
                mail('[email protected]','collection',$pro_collection);

            catch(Exception $e) {
                //Mage::log($e->getMessage(), null, 'collection.log');


the mail under the disableProducts function is working correctly but i am not able to get the product collection using this code $collection = Mage::getModel('catalog/product')->getCollection();

any body having any idea about what i have made wrong kindly point it out. Thanks.

  • I have tried checking the system.log and exception.log but they contain nothing.
    – Ravi Soni
    Apr 17, 2013 at 10:42

2 Answers 2


A collection will be empty until you access the data inside it (i.e. foreach loop), or call the ->load() method against it. After a collection has been loaded you can no longer edit the result set it contains, so this approach allows you to refine and filter the returned results by altering the select object contained inside the collection object. This in turn modifies the query run against the database and thus items you will find in the collection once it has been loaded.

If you instead use

$collection = Mage::getModel('catalog/product')->getCollection()->load();

you will find the collection then contains data. Bear in mind that dependant on the store, the catalog/product collection can be very large so I certainly wouldn't recommend emailing it's contents as this could be a huge amount of data - this is especially the case for a live store. If you are attempting to debug you should be using xdebug and an IDE such as netbeans in a local development environment to inspect objects and their contents.


try to use

$collection = $observer->getProduct(); 

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.