0

I am developing a custom module where an xml file will be created after order completion for each order.

I have called a function exportOrder on occuring of an event "sales_order_place_after". Following is the code of my function

public function exportOrder($observer) {
    $order = $observer->getEvent()->getOrder();
    Mage::getModel('meteorify_observerexample/export')->exportOrder($order);
    return true;
}

Now In Export.php file i have written the logic of creation of an xml file.Export.php file is placed in the folder Meteorify/Observerexample/Model/ folder.

Here i have called the function exportOrder from the file Export.php using Mage::getModel('meteorify_observerexample/export')->exportOrder($order); but i am getting the error

"Fatal error: Call to a member function exportOrder() on a non-object in /home/user_www/aliasgar/magentotesting/app/code/local/Meteorify/Observerexample/Model/Observer.php on line 6"

Can anyone help me on this ?

  • How does the config.xml file of your module look like? I have a hung the helpers alias is not set properly. – Marius Aug 12 '13 at 11:08
  • This is how my helper config looks "<helpers> <orderexport> <class>Meteorify_Observerexample_Helper</class> </orderexport> </helpers>" – Dexter Aug 12 '13 at 11:14
  • Models and events looks like this "<models> <meteorify_observerexample> <class>Observerexample_Model</class> </meteorify_observerexample> </models> <events> <checkout_onepage_controller_success_action> <observers> <sales_order_place_after> <type>singleton</type> <class>Meteorify_Observerexample_Model_Observer</class> <method>exportOrder</method> </sales_order_place_after> </observers> </checkout_onepage_controller_success_action> </events>" – Dexter Aug 12 '13 at 11:16
  • Please add the contents of config.xml to the question. It's easier to read and follow. – Marius Aug 12 '13 at 11:33
0

The problem is in the config.xml file in the declaration of the model alias.
In your case is:

<models>
    <meteorify_observerexample>
        <class>Observerexample_Model</class>
    </meteorify_observerexample>
</models> 

But it should be

<models>
    <meteorify_observerexample>
        <class>Meteorify_Observerexample_Model</class>
    </meteorify_observerexample>
</models>
  • Thanks for your reply it was a stupid mistake by me. As i am a newbie in magento, I repeatedly tend to make such mistakes. Now please can you guide me through this mistake too. In the file Export.php I have wrote the code for creating the order xml. Now i read from one of the article regarding fetching the orderdata using observer object. I am writing the code in the next comment – Dexter Aug 12 '13 at 11:55
  • Following is the code i have wrote "public function exportOrder($order){ $dirPath = Mage::getBaseDir('var').DS.'export'; //if the export directory does not exist, create it if (!is_dir($dirPath)) { mkdir($dirPath, 0777, true); } $data = $order->getData();" Here i am getting the error 'Fatal error: Call to a member function getData() on a non-object in /home/user_www/aliasgar/magentotesting/app/code/local/Meteorify/Observerexample/Model/Export.php on line 12' which is the line of code '$data = $order->getData()' – Dexter Aug 12 '13 at 11:57
  • @Dexter. That is a different issue. Please post an other question with your code and your problem. Don't mix them. – Marius Aug 12 '13 at 11: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.