3

I want to export data of a category when its save in magento system. So, I also create a module & create a event name which is catalog_category_save_commit_after. My code is like below..

<config>
<global>
 ....
<events>
        <catalog_category_save_commit_after>
            <observers>
                <category_category_observer>
                    <type>singleton</type>
                    <class>Feed_Category_Model_Category_Observer</class>
                    <method>saveCategoryData</method>
                </category_category_observer>
            </observers>
        </catalog_category_save_commit_after>
    </events>
</global>

class Feed_Category_Model_Category_Observer
{
    public function saveCategoryData($observer)
    {              

        $category = $observer->getEvent()->getDataObject();
        Mage::log($category);
        // or
        Mage::log($observer->getEvent()->getCategory());    

    }
 }

Both are return blank. Have any idea??

4
  • 1
    The code looks ok. Are you sure that the log is turned on? To be sure that something is logged, do it this way. Mage::log('what to log', null, 'system.log', true);
    – Marius
    Jul 9, 2014 at 11:10
  • @Marius, can you explain what is the purpose of NULL in your statement? Jul 9, 2014 at 11:24
  • 1
    That's the level for logging. If it's set to null it defaults to Zend_Log::DEBUG. Look in the Mage::log method for more details
    – Marius
    Jul 9, 2014 at 11:26
  • add magento log like Mage::log($category, null, 'observer_category_data.log'); . It's work
    – Shorabh
    Jul 20, 2018 at 11:51

2 Answers 2

3

I have used this in sales_order_place_after event

public function myMethod(Varien_Event_Observer $observer)
    {
        $data = $observer->getEvent()->getOrder();
        Mage::log($data , null, 'sales_order_place_data.log');   
}

Maybe it will be helps you.

You can try this

$data = $observer->getEvent()->getCategory();
Mage::log($data , null, 'sales_order_place_data.log');
3
  • Thanks for your response. but this is not a acceptable answer. I also used $data = $observer->getEvent()->getCategory();. Jul 9, 2014 at 11:09
  • Mage::log($data->debug()); Try this to print an object in log file.
    – Charlie
    Jul 9, 2014 at 11:12
  • @Supravat please try this Mage::log($data , null, 'observer_category_data.log');
    – Shorabh
    Jul 20, 2018 at 12:01
2

To see what kind of data is available the fastest way is to check where the dispachtEvent is called. This cheatsheet should help you with that.

If you open the class on line 334 you can see what data is passed. Looking at the code it should be something like this:

var_dump($observer->getDataObject()->getData());

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.