Script that grabs the customers are celebrating their birthday and sends them email.
Files:
1. MAGENTO_ROOT/birthday/birthday.php
2. MAGENTO_ROOT/app/etc/modules/Magazento_Bigzipper.xml – our small extension config
3. MAGENTO_ROOT/app/locale/ru_RU/template/email/birthday_default.html – email template with id birthday_default
4. MAGENTO_ROOT/app/code/local/Magazento/Bigzipper/etc.xml – settings, we register email template here
1. birthday.php
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
require_once('../app/Mage.php');
Mage::app('');
$daymonthNow = date('d').'-'.date('m');
$collection = Mage::getModel("customer/customer")
->getCollection()->addAttributeToSelect("*")
->addFieldToFilter("dob",array('notnull' => false));
foreach ($collection as $customer)
{
$dob = explode(' ',$customer->getDob());
$date = explode('-',$dob[0]);
$daymonthBirthday = $date[1].'-'.$date[2];
if ( $daymonthBirthday == $daymonthNow ) {
$customerName = mb_convert_case($customer->getFirstname(), MB_CASE_TITLE, "UTF-8");
$customerEmail = $customer->getEmail();
sendBirthdayEmail($customerEmail,$customerName);
}
}
function sendBirthdayEmail($customerName,$customerEmail) {
$storeId = Mage::app()->getStore()->getStoreId();
$mailTemplate = Mage::getModel('core/email_template');
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$storeId));
$emailId = 'birthday_default';
$mailTemplate->sendTransactional(
$emailId,
array('email'=>$customerEmail, 'name'=>$customerName),
$customerEmail,
null,
array(
'customer_name' => $customerName
)
);
}
?>
2. Magazento_Bigzipper.xml
<?xml version="1.0"?>
<config>
<modules>
<Magazento_Bigzipper>
<active>true</active>
<codePool>local</codePool>
</Magazento_Bigzipper>
</modules>
</config>
3. birthday_default.html
<?xml version="1.0"?>
<config>
<modules>
<Magazento_Bigzipper>
<active>true</active>
<codePool>local</codePool>
</Magazento_Bigzipper>
</modules>
</config>
4. config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Magazento_Bigzipper>
<version>1.0.2</version>
</Magazento_Bigzipper>
</modules>
<global>
<template>
<email>
<birthday_default>
<label>Birthday Default</label>
<file>birthday_default.html</file>
<type>html</type>
</birthday_default>
</email>
</template>
</global>
</config>