0

1) When user submits an "Email to Friend" form.

2) When user submits his email for Newsletter.

4

And awesome-but-non-obvious events strike again!

Both of your use cases involve user requests. There are always two unique events for actions. The sequence of method calls in a typical dispatch is as follows:

The automagic events are called in this action controller superclass in the preDispatch() and postDispatch() methods:

public function preDispatch()
{
    //snip...
    Mage::dispatchEvent('controller_action_predispatch_' . $this->getFullActionName(),
        array('controller_action' => $this));
}

and

public function postDispatch()
{
    //snip...
    Mage::dispatchEvent(
        'controller_action_postdispatch_'.$this->getFullActionName(),
        array('controller_action'=>$this)
    );
    //snip...
}

In the case of the email to a friend action, you want to capture the input from the user, which is POSTed to the Mage_Sendfriend_ProductController::sendmailAction(). Even though there is a redirect set on success (or on error), you can still capture the POST request by observing controller_action_postdispatch_sendfriend_product_sendmail. Of course, there's not a really graceful way of capturing whether the transaction was a success or a failure (checking session message storage for success or error is the only obvious way), but this should get you started.

The newsletter post is a similar case - that form action is pointed to Mage_Newsletter_SubscriberController::newAction(), so you can observe controller_action_postdispatch_newsletter_subscriber_new. However, this action involves a model with some business logic (see Mage_Newsletter_Model_Subscriber::subscribe(), and when the instance is saved, it will dispatch automagic events of its own as part of Magento's ORM event hooks (namely newsletter_subscriber_save_before and newsletter_subscriber_save_after).

So, like my friend Vinai says, Magento is "all about options," including when it comes to hooking into newsletter subscriptions.

0

Well I searched for Mage::dispatchEvent(' in magento folder using my editor and found:

Mage::dispatchEvent('sendfriend_product', array('product' => $product));

But I did not found anything for Newsletter.

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.