Is there a way I can send an email notification to user whenever magento recurring profile is created??
1 Answer
Absolutely... Check out how to create an event observer Magento Event Observers
Then take a look at the events fired (find dispatchEvent) in \Mage_Checkout_Model_Type_Onepage
If you don't want to poke around, the event you want is 'checkout_type_onepage_save_order_after' and if you search that Onepage class for it you'll see where Magento sends the normal order email... Since the order is passed in the event, from your observer you can call $order->getItems() and through an if statement in your observer function, when you match a recurring profile you can send an email by referencing the email's template id and sending it.
function sendHafeleOrderEmail($sendTo, $copyTo, $copyMethod, $storeId, $templateId)
{
// Retrieve Hafele email template id
$templateId = $templateId = $templateId;
//set mailer and emailinfo
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($sendTo);
if ($copyTo && $copyMethod == 'bcc') {
// Add bcc to customer email
foreach ($copyTo as $email) {
$emailInfo->addBcc($email);
}
}
$mailer->addEmailInfo($emailInfo);
// Email copies are sent as separated emails if their copy method is 'copy'
if ($copyTo && $copyMethod == 'copy') {
foreach ($copyTo as $email) {
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($email);
$mailer->addEmailInfo($emailInfo);
}
}
// Set all required params and send emails
$mailer->setSender(Mage_Sales_Model_Order::XML_PATH_EMAIL_IDENTITY, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId($templateId);
//If any at all
/* $mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml
)
); */
$mailer->send();
return true;
}