// Merge -> revision 9061

This commit is contained in:
rMalie
2011-10-05 15:21:55 +00:00
parent d8f04cedb7
commit bbc6c6bdc4
53 changed files with 795 additions and 456 deletions

View File

@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -44,7 +44,7 @@ class ReferralProgram extends Module
$this->description = $this->l('Integrate a referral program system into your shop.');
if (Configuration::get('REFERRAL_DISCOUNT_TYPE') == 1 AND !Configuration::get('REFERRAL_PERCENTAGE'))
$this->warning = $this->l('Please specify an amount for referral program vouchers.');
if ($this->id)
{
$this->_configuration = Configuration::getMultiple(array('REFERRAL_NB_FRIENDS', 'REFERRAL_ORDER_QUANTITY', 'REFERRAL_DISCOUNT_TYPE', 'REFERRAL_DISCOUNT_VALUE'));
@@ -68,11 +68,11 @@ class ReferralProgram extends Module
OR !$this->registerHook('adminCustomers') OR !$this->registerHook('createAccount')
OR !$this->registerHook('createAccountForm') OR !$this->registerHook('customerAccount'))
return false;
/* Define a default value for fixed amount vouchers, for each currency */
foreach (Currency::getCurrencies() AS $currency)
Configuration::updateValue('REFERRAL_DISCOUNT_VALUE_'.(int)($currency['id_currency']), 5);
/* Define a default value for the percentage vouchers */
Configuration::updateValue('REFERRAL_PERCENTAGE', 5);
@@ -107,7 +107,7 @@ class ReferralProgram extends Module
foreach (Currency::getCurrencies() AS $currency)
$result = $result AND Configuration::deleteByName('REFERRAL_DISCOUNT_VALUE_'.(int)($currency['id_currency']));
if (!parent::uninstall() OR !$this->uninstallDB() OR !$this->removeMail() OR !$result
OR !Configuration::deleteByName('REFERRAL_PERCENTAGE') OR !Configuration::deleteByName('REFERRAL_ORDER_QUANTITY')
OR !Configuration::deleteByName('REFERRAL_PERCENTAGE') OR !Configuration::deleteByName('REFERRAL_ORDER_QUANTITY')
OR !Configuration::deleteByName('REFERRAL_DISCOUNT_TYPE') OR !Configuration::deleteByName('REFERRAL_NB_FRIENDS')
OR !Configuration::deleteByName('REFERRAL_DISCOUNT_DESCRIPTION'))
return false;
@@ -273,7 +273,7 @@ class ReferralProgram extends Module
<td>'.(Configuration::get('PS_CURRENCY_DEFAULT') == $currency['id_currency'] ? '<span style="font-weight: bold;">' : '').htmlentities($currency['name'], ENT_NOQUOTES, 'utf-8').(Configuration::get('PS_CURRENCY_DEFAULT') == $currency['id_currency'] ? '<span style="font-weight: bold;">' : '').'</td>
<td><input type="text" name="discount_value['.(int)($currency['id_currency']).']" id="discount_value['.(int)($currency['id_currency']).']" value="'.Tools::safeOutput(Tools::getValue('discount_value['.(int)($currency['id_currency']).']', Configuration::get('REFERRAL_DISCOUNT_VALUE_'.(int)($currency['id_currency'])))).'" style="width: 50px; text-align: right;" /> '.$currency['sign'].'</td>
</tr>';
$this->_html .= '
</table>
<p>
@@ -312,7 +312,7 @@ class ReferralProgram extends Module
$isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en');
$ad = dirname($_SERVER["PHP_SELF"]);
$this->_html .= '
<script type="text/javascript">
<script type="text/javascript">
var iso = \''.$isoTinyMCE.'\' ;
var pathCSS = \''._THEME_CSS_DIR_.'\' ;
var ad = \''.$ad.'\' ;
@@ -346,7 +346,7 @@ class ReferralProgram extends Module
public function hookShoppingCart($params)
{
include_once(dirname(__FILE__).'/ReferralProgramModule.php');
if (!isset($params['cart']->id_customer))
return false;
if (!($id_referralprogram = ReferralProgramModule::isSponsorised((int)($params['cart']->id_customer), true)))
@@ -357,7 +357,7 @@ class ReferralProgram extends Module
$discount = new Discount($referralprogram->id_discount);
if (!Validate::isLoadedObject($discount))
return false;
if ($params['cart']->checkDiscountValidity($discount, $params['cart']->getDiscounts(), $params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), $params['cart']->getProducts(), false, $this->context) === false)
{
$this->context->smarty->assign(array('discount_display' => Discount::display($discount->value, $discount->id_discount_type, new Currency($params['cookie']->id_currency)), 'discount' => $discount));
@@ -374,7 +374,7 @@ class ReferralProgram extends Module
{
return $this->display(__FILE__, 'my-account.tpl');
}
public function hookMyAccountBlock($params)
{
return $this->hookCustomerAccount($params);
@@ -387,7 +387,7 @@ class ReferralProgram extends Module
public function hookCreateAccountForm($params)
{
include_once(dirname(__FILE__).'/ReferralProgramModule.php');
if (Configuration::get('PS_CIPHER_ALGORITHM'))
$cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
else
@@ -427,7 +427,7 @@ class ReferralProgram extends Module
$sponsorEmail = $postVars['referralprogram'];
if (!Validate::isEmail($sponsorEmail) OR $sponsorEmail == $newCustomer->email)
return false;
$sponsor = new Customer();
if ($sponsor = $sponsor->getByEmail($sponsorEmail, NULL, $this->context))
{
@@ -458,9 +458,25 @@ class ReferralProgram extends Module
$discount = new Discount((int)$referralprogram->id_discount);
if (Validate::isLoadedObject($discount))
{
$data = array('{firstname}' => $newCustomer->firstname, '{lastname}' => $newCustomer->lastname, '{voucher_num}' => $discount->name,
'{voucher_amount}' => Tools::displayPrice((float)Configuration::get('REFERRAL_DISCOUNT_VALUE_'.(int)$this->context->currency->id), (int)Configuration::get('PS_CURRENCY_DEFAULT')));
Mail::Send($this->context->language->id, 'referralprogram-voucher', Mail::l('Congratulations!'), $data, $newCustomer->email, $newCustomer->firstname.' '.$newCustomer->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/');
$data = array(
'{firstname}' => $newCustomer->firstname,
'{lastname}' => $newCustomer->lastname,
'{voucher_num}' => $discount->name,
'{voucher_amount}' => (Configuration::get('REFERRAL_DISCOUNT_TYPE') == 2 ? Tools::displayPrice((float)Configuration::get('REFERRAL_DISCOUNT_VALUE_'.(int)$this->context->currency->id), (int)Configuration::get('PS_CURRENCY_DEFAULT')) : (float)Configuration::get('REFERRAL_PERCENTAGE').'%'));
Mail::Send(
(int)$cookie->id_lang,
'referralprogram-voucher',
Mail::l('Congratulations!'),
$data,
$newCustomer->email,
$newCustomer->firstname.' '.$newCustomer->lastname,
strval(Configuration::get('PS_SHOP_EMAIL')),
strval(Configuration::get('PS_SHOP_NAME')),
null,
null,
dirname(__FILE__).'/mails/'
);
}
}
return true;
@@ -476,7 +492,7 @@ class ReferralProgram extends Module
public function hookAdminCustomers($params)
{
include_once(dirname(__FILE__).'/ReferralProgramModule.php');
$customer = new Customer((int)$params['id_customer']);
if (!Validate::isLoadedObject($customer))
die (Tools::displayError('Incorrect object Customer.'));
@@ -539,7 +555,7 @@ class ReferralProgram extends Module
return die(Tools::displayError('Incorrect object Order.'));
include_once(dirname(__FILE__).'/ReferralProgramModule.php');
$customer = new Customer((int)$params['objOrder']->id_customer);
$stats = $customer->getStats();
$nbOrdersCustomer = (int)$stats['nb_orders'] + 1; // hack to count current order
@@ -570,9 +586,9 @@ class ReferralProgram extends Module
$order = new Order((int)($params['id_order']));
if ($order AND !Validate::isLoadedObject($order))
die(Tools::displayError('Incorrect object Order.'));
include_once(dirname(__FILE__).'/ReferralProgramModule.php');
$customer = new Customer((int)$order->id_customer);
$stats = $customer->getStats();
$nbOrdersCustomer = (int)$stats['nb_orders'] + 1; // hack to count current order