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

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

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

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

'.$this->l('The minimal 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 its 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 its loyalty, in other words to make him come back in 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 in your webshop regularly.').'

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