Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacquesbh/3132212 to your computer and use it in GitHub Desktop.
Save jacquesbh/3132212 to your computer and use it in GitHub Desktop.
[blog] The transactional emails in Magento (http://jacques.sh/creer-un-email-transactionnel-sur-magento.html)
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Jbh_Demo>
<version>0.1.0</version>
</Jbh_Demo>
</modules>
<global>
<models>
<jbh_demo>
<class>Jbh_Demo_Model</class>
</jbh_demo>
</models>
<template>
<email>
<jbh_demo_email_happyday translate="label" module="jbh_demo">
<label>Happy Birthday!</label>
<file>jbh_demo/happyday.html</file>
<type>text</type>
</jbh_demo_email_happyday>
</email>
</template>
</global>
<default>
<jbh_demo>
<email>
<identity>general</identity>
<happyday>jbh_demo_email_happyday</happyday>
</email>
</jbh_demo>
</default>
</config>
<?php
/**
* Email Model
* @package Jbh_Demo
*/
class Jbh_Demo_Model_Email extends Mage_Core_Model_Abstract
{
/**
* Configuration key for the email's identity
* @const CONFIG_KEY_EMAIL_IDENTITY string
*/
const CONFIG_KEY_EMAIL_IDENTITY = 'jbh_demo/email/identity';
/**
* Configuration key for the email's template "happyday"
* @const CONFIG_KEY_EMAIL_HAPPYDAY string
*/
const CONFIG_KEY_EMAIL_HAPPYDAY = 'jbh_demo/email/happyday';
/**
* Send the email happyday to the customer
* @param Mage_Customer_Model_Customer $customer The customer
* @throws Mage_Core_Exception
* @access public
* @return Jbh_Demo_Model_Email
*/
public function happyday($customer = null)
{
// Retrieve the customer
if (is_null($customer)) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
} elseif (!($customer instanceof Mage_Customer_Model_Customer)) {
$customer = Mage::getModel('customer/customer')->load((int) $customer);
}
// The customer is required for our email
if (!$customer->getId()) {
Mage::throwException('Customer needed for this email.');
}
/*
* Send the email :)
*
* - Get the template
* - Send transactional
*/
$emailTemplate = Mage::getModel('core/email_template');
/* @var $emailTemplate Mage_Core_Model_Email_Template */
return $emailTemplate
->setDesignConfig(array('area' => 'frontend'))
->sendTransactional(
Mage::getStoreConfig(self::CONFIG_KEY_EMAIL_HAPPYDAY),
Mage::getStoreConfig(self::CONFIG_KEY_EMAIL_IDENTITY),
$customer->getEmail(),
null,
array(
'customer' => $customer
)
);
}
}
<?xml version="1.0" encoding="utf-8" ?>
<config>
<modules>
<Jbh_Demo>
<active>true</active>
<codePool>local</codePool>
</Jbh_Demo>
</modules>
</config>
<!--@subject Joyeux anniversaire ! @-->
Bonjour {{htmlescape var=$customer.name}},
Aujourd'hui est un jour spécial.
Toute l'équipe de {{var store.getFrontendName()}} vous souhaite un joyeux anniversaire !
A bientôt sur notre boutique,
L'équipe de {{var store.getFrontendName()}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment