Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

HALP! This is my first attempt at this kind of thing. It seems that the function won't fire when the event happens. (Eventually, what's supposed to happen is that when the event

Mage::dispatchEvent('nextbits_form_save_after',array('form_data'=>$params, 'form_model'=>$formModel));

occurs, the form data will be routed to appropriate people based on the data contained in the form.....)

I haven't written that code yet, but I don't see the observer catching the event and doing anything at all. What is the problem with my event/observer structures?

Observer.php: [\app\code\local\Westcott\EmailRouter\Model\Observer.php]

<?php

class Westcott_EmailRouter_Model_Observer {

    public function Notify_by_Mail($observer){

        if (isset($observer['form_data'])) {
            $form_data = $observer['form_data'];
            //$form_model = $observer['form_model'];

            foreach ($form_data as $key =>$fd) {
                //Do something with the form data
                echo "K: ".$key." => ".$fd."<br/>";
            }
            /*
            foreach ($form_model as $key =>$fm) {
                //Do something with the form data
                echo "K: ".$key." => ".$fm."<br/>";
            }
            */
        } else {
            //Do something else with the form data...
        }

    }

    echo "Hello!!";
}

Westcott_EmailRouter.xml: [\app\etc\modules\Westcott_EmailRouter.xml]

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

config.xml: [\app\code\local\Westcott\EmailRouter\etc\config.xml]

<?xml version="1.0"?>
    <config>
        <modules>
            <Westcott_EmailRouter>
                <version>0.1.0</version>
            </Westcott_EmailRouter>
        </modules>
        <global>
            <models>
                <emailrouter>
                    <class>Westcott_EmailRouter_Model</class>
                </emailrouter>
            </models>
            <events>
                <nextbits_form_save_after>
                    <observers>
                        <Westcott_EmailRouter>
                            <!--<type>singleton</type>-->
                            <class>westcott_emailrouter/observer</class>
                            <method>Notify_by_Mail</method>
                        </Westcott_EmailRouter>
                    </observers>
                </nextbits_form_save_after>
            </events>   
        </global>
    </config>
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

First make sure the event your observing exits:

grep -rin -B2 -A2 "Mage::dispatchEvent" app/* > events.txt

View events.txt and search for nextbits_form_save_after

Second, as others mentioned your observer method isn't defined in your Observer.php

<method> should be doNotifyBySubmittedContent instead.

You can also get a list of events with a quick core hack:

You may also want to verify that the eventDispatch you're trying to observer is in fact being called during the stack as well.

* EDIT *


$observer will not have ['form_data'] you'll need to get the Event Request.

$request = $observer->getEvent()->getRequest()->getParams();
if(is_set($request['form_data'])) {

* EDIT #2 *


Just realized I had getParams() as the dispatched Event is magic getter/setter NOT a URI request.

Something like this should work if you're sure the event is being dispatched and form data is present:

$event = $observer->getEvent(); $formData = $event->getFormData(); // magic get/set $formModel = $event->getFormModel(); // magic get/set zend_debug::dump($formData); zend_debug::dump($formModel);

share|improve this answer
1  
OK... Thanks, Boomer. I assumed the event was in there but it wasn't for some reason. I purchased the extension and was told by the vendor's support staff that it was there....I'll have to take that up with them now, I guess. Also, I know about the observer method. (last minute edit while posting, etc.) Is there another problem with the class declaration? –  g-man1066 Apr 9 at 20:48
    
Quick additional note, zend_debug::dump(get_class_methods($observer->getEvent())); Will give you a list of available methods the observed event has. –  B00MER Apr 9 at 21:36
    
Thanks, @B00MER, I'm not sure what to do with that. I get "syntax errors near unexpected token `get_class_methods'".... I found a comment you posted elsewhere: "The approach I usually take is, a quick edit/save/revert to app/code/core/Mage/Core/Model/App.php and mage::log($eventName,null,'events.txt',true); to the dispatchEvent method. Load the page I'm trying to observe. Obviously don't leave this as is and revert once your var/logs/events.txt is created. Dirty, yes. Quick, yes. :) – B00MER Apr 15 '13 at 20:39" Do I read this correctly as temporarily adding the mage::log() to App.php? –  g-man1066 Apr 10 at 13:19
1  
Not sure unfortunatly, perhaps a good reference may help: inchoo.net/ecommerce/magento/… some other events you may be able to hook into. –  B00MER Apr 11 at 23:09
1  
$event = $observer->getEvent(); $formData = $event->getFormData(); // magic get/set $formModel = $event->getFormModel(); // magic get/set zend_debug::dump($formData); zend_debug::dump($formModel); Was what I needed. Thank you, @B00MER –  g-man1066 Apr 16 at 14:45
show 4 more comments

Hello There are issue in events tags... model class declaretion also Notify_by_Mail is not exiting in observer.php

....
<observers>
                        <westcott_emailRouter>

                            <class>emailrouter/observer</class>
                            <method>doNotifyBySubmittedContent</method>
                        </westcott_emailRouter>
                    </observers>
...
share|improve this answer
    
I wanted to answer, when I saw this. In other words: You named your model group name as emailrouter, but you declare your observer class alias with westcott_emailrouter/observer. The latter should be emailrouter/observer. –  nevvermind Apr 9 at 20:37
    
i cannot understand ,what u asked –  Amit Bera Apr 10 at 13:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.