name = 'birthdaypresent';
$this->tab = 'Tools';
$this->version = 1.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', intval(Tools::getValue('bp_active')));
Configuration::updateValue('BIRTHDAY_DISCOUNT_TYPE', intval(Tools::getValue('id_discount_type')));
Configuration::updateValue('BIRTHDAY_DISCOUNT_VALUE', floatval(Tools::getValue('discount_value')));
Configuration::updateValue('BIRTHDAY_MINIMAL_ORDER', floatval(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()->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 = intval($user['id_customer']);
$voucher->id_discount_type = intval(Configuration::get('BIRTHDAY_DISCOUNT_TYPE'));
$voucher->name = 'BIRTHDAY-'.intval($voucher->id_customer).'-'.date('Y');
$voucher->description[intval(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(intval(Configuration::get('PS_LANG_DEFAULT')), 'birthday', $this->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();
}
}
}
?>