* @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 = '
'.$this->displayName.'

'.$this->l('Create a voucher for customers celebrating their birthday and having at least one valid order').'

'.$this->l('Additionally, you have to set a CRON rule which calls the file').'
'.Tools::getProtocol().$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/birthdaypresent/cron.php '.$this->l('every day').'

'.$this->l('Either the monetary amount or the %, depending on Type selected above').'

'.$this->l('The minimum order amount needed to use the voucher').'

* '.$this->l('Required field').'

'.$this->l('Guide').'

'.$this->l('Develop clients\' loyalty').'

'.$this->l('Offering a present to a client is a means of securing their loyalty.').'

'.$this->l('What should you do?').'

'.$this->l('Keeping a client is more profitable than capturing a new one. Thus, it is necessary to develop their loyalty, in other words to make them want to come back to your webshop.').'
'.$this->l('Word of mouth is also a means to get new satisfied clients; a dissatisfied one won\'t attract new clients.').'
'.$this->l('In order to achieve this goal you can organize: ').'

'.$this->l('These operations encourage clients to buy and also to come back to your webshop regularly.').'

'; 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(); } } }