1

Im trying to send email notifications to customer in magento for custom events.

ie) Whenever the admin changes the status of a custom article, from Approve to Disapprove, there should be an email trigger to the customer.

I could get an email for order canceled event, i need to achieve for the above scenario.

I have tried below:

app\code\local\Magenshop\Recipe\etc\config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Magenshop_Recipe>
        <version>1.0.0</version>
    </Magenshop_Recipe>
</modules>
<global>
   <events>
       <recipe_admin_approve>
            <observers>
                <recipe>
                    <type>singleton</type>
                    <class>recipe/status</class>  
                    <method>statusChangedApproved</method>
                </recipe>
            </observers>
        </recipe_admin_approve>
    </events>
</global>

So now when admin changes the status here, i should get a notification

enter image description here

\app\code\local\Magenshop\Recipe\Model\Status.php

<?php

class Magenshop_Recipe_Model_Status extends Varien_Object
{
const STATUS_ENABLED    = 1;
const STATUS_DISABLED   = 0;
const STATUS_REQUESTORM = 3;
static public function getOptionArray()
{
    return array(
        self::STATUS_ENABLED    => Mage::helper('recipe')->__('Approved'),
        self::STATUS_DISABLED   => Mage::helper('recipe')->__('UnApproved'),
        //self::STATUS_REQUESTORM   => Mage::helper('recipe')->__('Remove')
    );
}

static public function toOptionArray()
{
    return array(
        self::STATUS_ENABLED    => Mage::helper('recipe')->__('Approved'),
        self::STATUS_DISABLED   => Mage::helper('recipe')->__('UnApproved'),
        //self::STATUS_REQUESTORM   => Mage::helper('recipe')->__('Remove')
    );
}

//custom notification methods
public function statusChangedApproved()
{
        echo 'status changed';die;
}

}

?>
  • What's your question exactly? – Julien Lachal Dec 14 '16 at 9:34
  • I need to get a notification @Julien for my custom events whenever admin approves a product. ie when there is a status change – Sushivam Dec 14 '16 at 9:37
  • Are you sure the event is fired? – Julien Lachal Dec 14 '16 at 9:39
  • no the method in observer is also not getting called where i have given 'die' and also event is not getting called! – Sushivam Dec 14 '16 at 10:13
1

The function statusChangedApproved() will only be called once the recipe_admin_approve event is fired. Somewhere is your code (or the module's code), you need to find/add

Mage::dispatchEvent('recipe_admin_approve', array('whatever' => 'anObjectOrValue'));
|improve this answer|||||
0

My advice when sending emails is to look into extensions that handle emails. Sending right out of your own Magento will cause your mails to end up in Junk or Spam or half won't arrive at their destination (our experience at least). Use a free extension like SendGrid or Magepal_GmailSmtpApp which always assure that the email arrives properly and is not marked as spam.

|improve this answer|||||
0

As Julien Lachal already wrote - you have to dispatch your event.

To send an email notification you need to put the following code into your statusChangedApproved() method in your observer class:

Mage::getModel('core/email_template')
    ->sendTransactional('your_template_identifier',
        array(
            'name' => 'Sender`s name',
            'email' => 'sender@example.com'
        ),
        'recipient@example.com',
        'Recipient Name',
        array(
            'any' => $vars,
            'you' => $likeTo,
            'pass' => $toTheMailTemplate
        ),
        $storeId);

Thats it. Be sure that your mail smtp is configured correctly. You need to define your mail template 'your_template_identifier' in the config.xml like:

</global>
    </template>
        <email>
            <your_template_identifier translate="label" module="notify">
                <label>Your email template</label>
                <file>recipe/your_email_template.html</file>
                <type>html</type>
            </your_template_identifier>
        </email>
    </template>
</global>

The template file is located in locale/en_US/template/email/recipe/your_email_template.html

I hope this will help anybody with the same problem.

There is also an easy solution to manage complex notification for any event in Magento with detailed reports or plain notification messages. It also supports to apply any information in the notification content: https://grafzahl.io/notify-module/

|improve this answer|||||

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.