* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6889 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_CAN_LOAD_FILES_'))
exit;
class BirthdayPresent extends Module
{
private $_html = '';
function __construct()
{
$this->name = 'birthdaypresent';
$this->tab = 'pricing_promotion';
$this->version = 1.0;
$this->author = 'PrestaShop';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Birthday Present');
$this->description = $this->l('Offer your clients birthday presents automatically');
}
public function getContent()
{
global $cookie, $currentIndex;
if (Tools::isSubmit('submitBirthday'))
{
Configuration::updateValue('BIRTHDAY_ACTIVE', (int)(Tools::getValue('bp_active')));
Configuration::updateValue('BIRTHDAY_DISCOUNT_TYPE', (int)(Tools::getValue('id_discount_type')));
Configuration::updateValue('BIRTHDAY_DISCOUNT_VALUE', (float)(Tools::getValue('discount_value')));
Configuration::updateValue('BIRTHDAY_MINIMAL_ORDER', (float)(Tools::getValue('minimal_order')));
Tools::redirectAdmin($currentIndex.'&configure=birthdaypresent&token='.Tools::getValue('token').'&conf=4');
}
$this->_html = '
';
return $this->_html;
}
public function createTodaysVouchers()
{
$users = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT DISTINCT c.id_customer, firstname, lastname, email
FROM '._DB_PREFIX_.'customer c
LEFT JOIN '._DB_PREFIX_.'orders o ON (c.id_customer = o.id_customer)
WHERE o.valid = 1
AND c.birthday LIKE \'%'.date('-m-d').'\'');
foreach ($users as $user)
{
$voucher = new Discount();
$voucher->id_customer = (int)($user['id_customer']);
$voucher->id_discount_type = (int)(Configuration::get('BIRTHDAY_DISCOUNT_TYPE'));
$voucher->name = 'BIRTHDAY-'.(int)($voucher->id_customer).'-'.date('Y');
$voucher->description[(int)(Configuration::get('PS_LANG_DEFAULT'))] = $this->l('Your birthday present !');
$voucher->value = Configuration::get('BIRTHDAY_DISCOUNT_VALUE');
$voucher->quantity = 1;
$voucher->quantity_per_user = 1;
$voucher->cumulable = 1;
$voucher->cumulable_reduction = 1;
$voucher->date_from = date('Y-m-d');
$voucher->date_to = strftime('%Y-%m-%d', strtotime('+1 month'));
$voucher->minimal = Configuration::get('BIRTHDAY_MINIMAL_ORDER');
$voucher->active = true;
if ($voucher->add())
Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')), 'birthday', Mail::l('Happy birthday!'), array('{firstname}' => $user['firstname'], '{lastname}' => $user['lastname']), $user['email'], NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/');
else
echo Db::getInstance()->getMsgError();
}
}
}