Merge branch 'ticket-10133' into develop

This commit is contained in:
Marion Muszynski 2016-09-15 10:52:08 +02:00
commit dbcbfacae3

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@ -34,7 +34,7 @@ if (!defined('_PS_VERSION_'))
* - Bad behaviour when an order is cancelled after an order return * - Bad behaviour when an order is cancelled after an order return
* - We shouldn't use $cookie->id_currency in all situations * - We shouldn't use $cookie->id_currency in all situations
*/ */
class Loyalty extends Module class Loyalty extends Module
{ {
function __construct() function __construct()
@ -55,7 +55,7 @@ class Loyalty extends Module
private function instanceDefaultStates() private function instanceDefaultStates()
{ {
include_once(dirname(__FILE__).'/LoyaltyStateModule.php'); include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
/* Recover default loyalty status save at module installation */ /* Recover default loyalty status save at module installation */
$this->loyaltyStateDefault = new LoyaltyStateModule(LoyaltyStateModule::getDefaultId()); $this->loyaltyStateDefault = new LoyaltyStateModule(LoyaltyStateModule::getDefaultId());
$this->loyaltyStateValidation = new LoyaltyStateModule(LoyaltyStateModule::getValidationId()); $this->loyaltyStateValidation = new LoyaltyStateModule(LoyaltyStateModule::getValidationId());
@ -67,24 +67,24 @@ class Loyalty extends Module
function install() function install()
{ {
include_once(dirname(__FILE__).'/LoyaltyStateModule.php'); include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
if (!parent::install() if (!parent::install()
OR !$this->installDB() OR !$this->installDB()
OR !$this->registerHook('extraRight') OR !$this->registerHook('extraRight')
OR !$this->registerHook('updateOrderStatus') OR !$this->registerHook('updateOrderStatus')
OR !$this->registerHook('newOrder') OR !$this->registerHook('newOrder')
OR !$this->registerHook('adminCustomers') OR !$this->registerHook('adminCustomers')
OR !$this->registerHook('shoppingCart') OR !$this->registerHook('shoppingCart')
OR !$this->registerHook('orderReturn') OR !$this->registerHook('orderReturn')
OR !$this->registerHook('cancelProduct') OR !$this->registerHook('cancelProduct')
OR !$this->registerHook('customerAccount') OR !$this->registerHook('customerAccount')
OR !Configuration::updateValue('PS_LOYALTY_PERCENT_VALUE', '1.75') OR !Configuration::updateValue('PS_LOYALTY_PERCENT_VALUE', '1.75')
OR !Configuration::updateValue('PS_LOYALTY_MINIMAL', 0) OR !Configuration::updateValue('PS_LOYALTY_MINIMAL', 0)
OR !Configuration::updateValue('PS_LOYALTY_NONE_AWARD', '1') OR !Configuration::updateValue('PS_LOYALTY_NONE_AWARD', '1')
) { ) {
return false; return false;
} }
$defaultTranslations = array('en' => 'Loyalty reward', 'fr' => 'Récompense fidélité'); $defaultTranslations = array('en' => 'Loyalty reward', 'fr' => 'Récompense fidélité');
$conf = array((int)Configuration::get('PS_LANG_DEFAULT') => $this->l('Loyalty reward')); $conf = array((int)Configuration::get('PS_LANG_DEFAULT') => $this->l('Loyalty reward'));
foreach (Language::getLanguages() AS $language) foreach (Language::getLanguages() AS $language)
@ -155,15 +155,15 @@ class Loyalty extends Module
return true; return true;
} }
function uninstall() function uninstall()
{ {
if (!parent::uninstall() OR !$this->uninstallDB() if (!parent::uninstall() OR !$this->uninstallDB()
OR !Configuration::deleteByName('PS_LOYALTY_PERCENT_VALUE') OR !Configuration::deleteByName('PS_LOYALTY_PERCENT_VALUE')
OR !Configuration::deleteByName('PS_LOYALTY_NONE_AWARD') OR !Configuration::deleteByName('PS_LOYALTY_NONE_AWARD')
OR !Configuration::deleteByName('PS_LOYALTY_MINIMAL') OR !Configuration::deleteByName('PS_LOYALTY_MINIMAL')
OR !Configuration::deleteByName('PS_LOYALTY_VOUCHER_CATEGORY') OR !Configuration::deleteByName('PS_LOYALTY_VOUCHER_CATEGORY')
OR !Configuration::deleteByName('PS_LOYALTY_VOUCHER_DETAILS') OR !Configuration::deleteByName('PS_LOYALTY_VOUCHER_DETAILS')
) { ) {
return false; return false;
} }
@ -186,7 +186,7 @@ class Loyalty extends Module
{ {
$defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
$languages = Language::getLanguages(); $languages = Language::getLanguages();
$this->_errors = array(); $this->_errors = array();
if (!is_array(Tools::getValue('categoryBox')) OR !sizeof(Tools::getValue('categoryBox'))) if (!is_array(Tools::getValue('categoryBox')) OR !sizeof(Tools::getValue('categoryBox')))
$this->_errors[] = $this->l('You must choose at least one category for voucher\'s action'); $this->_errors[] = $this->l('You must choose at least one category for voucher\'s action');
@ -196,10 +196,10 @@ class Loyalty extends Module
Configuration::updateValue('PS_LOYALTY_PERCENT_VALUE', (float)(Tools::getValue('discount_value'))); Configuration::updateValue('PS_LOYALTY_PERCENT_VALUE', (float)(Tools::getValue('discount_value')));
Configuration::updateValue('PS_LOYALTY_NONE_AWARD', (int)(Tools::getValue('PS_LOYALTY_NONE_AWARD'))); Configuration::updateValue('PS_LOYALTY_NONE_AWARD', (int)(Tools::getValue('PS_LOYALTY_NONE_AWARD')));
Configuration::updateValue('PS_LOYALTY_MINIMAL', (float)(Tools::getValue('minimal'))); Configuration::updateValue('PS_LOYALTY_MINIMAL', (float)(Tools::getValue('minimal')));
$this->loyaltyStateValidation->id_order_state = (int)(Tools::getValue('id_order_state_validation')); $this->loyaltyStateValidation->id_order_state = (int)(Tools::getValue('id_order_state_validation'));
$this->loyaltyStateCancel->id_order_state = (int)(Tools::getValue('id_order_state_cancel')); $this->loyaltyStateCancel->id_order_state = (int)(Tools::getValue('id_order_state_cancel'));
$arrayVoucherDetails = array(); $arrayVoucherDetails = array();
foreach ($languages AS $language) foreach ($languages AS $language)
{ {
@ -213,23 +213,23 @@ class Loyalty extends Module
if (empty($arrayVoucherDetails[$defaultLanguage])) if (empty($arrayVoucherDetails[$defaultLanguage]))
$arrayVoucherDetails[$defaultLanguage] = ' '; $arrayVoucherDetails[$defaultLanguage] = ' ';
Configuration::updateValue('PS_LOYALTY_VOUCHER_DETAILS', $arrayVoucherDetails); Configuration::updateValue('PS_LOYALTY_VOUCHER_DETAILS', $arrayVoucherDetails);
if (empty($this->loyaltyStateDefault->name[$defaultLanguage])) if (empty($this->loyaltyStateDefault->name[$defaultLanguage]))
$this->loyaltyStateDefault->name[$defaultLanguage] = ' '; $this->loyaltyStateDefault->name[$defaultLanguage] = ' ';
$this->loyaltyStateDefault->save(); $this->loyaltyStateDefault->save();
if (empty($this->loyaltyStateValidation->name[$defaultLanguage])) if (empty($this->loyaltyStateValidation->name[$defaultLanguage]))
$this->loyaltyStateValidation->name[$defaultLanguage] = ' '; $this->loyaltyStateValidation->name[$defaultLanguage] = ' ';
$this->loyaltyStateValidation->save(); $this->loyaltyStateValidation->save();
if (empty($this->loyaltyStateCancel->name[$defaultLanguage])) if (empty($this->loyaltyStateCancel->name[$defaultLanguage]))
$this->loyaltyStateCancel->name[$defaultLanguage] = ' '; $this->loyaltyStateCancel->name[$defaultLanguage] = ' ';
$this->loyaltyStateCancel->save(); $this->loyaltyStateCancel->save();
if (empty($this->loyaltyStateConvert->name[$defaultLanguage])) if (empty($this->loyaltyStateConvert->name[$defaultLanguage]))
$this->loyaltyStateConvert->name[$defaultLanguage] = ' '; $this->loyaltyStateConvert->name[$defaultLanguage] = ' ';
$this->loyaltyStateConvert->save(); $this->loyaltyStateConvert->save();
if (empty($this->loyaltyStateNoneAward->name[$defaultLanguage])) if (empty($this->loyaltyStateNoneAward->name[$defaultLanguage]))
$this->loyaltyStateNoneAward->name[$defaultLanguage] = ' '; $this->loyaltyStateNoneAward->name[$defaultLanguage] = ' ';
$this->loyaltyStateNoneAward->save(); $this->loyaltyStateNoneAward->save();
@ -283,7 +283,7 @@ class Loyalty extends Module
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"> <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
<fieldset> <fieldset>
<legend>'.$this->l('Settings').'</legend> <legend>'.$this->l('Settings').'</legend>
<label>'.$this->l('Ratio').'</label> <label>'.$this->l('Ratio').'</label>
<div class="margin-form"> <div class="margin-form">
<label for="discount_value" class="t">'.$this->l('Discount by total cart').'</label> <label for="discount_value" class="t">'.$this->l('Discount by total cart').'</label>
@ -344,11 +344,11 @@ class Loyalty extends Module
$indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : $index; $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : $index;
// Translations are not automatic for the moment ;) // Translations are not automatic for the moment ;)
$trads = array( $trads = array(
'Home' => $this->l('Home'), 'Home' => $this->l('Home'),
'selected' => $this->l('selected'), 'selected' => $this->l('selected'),
'Collapse All' => $this->l('Collapse All'), 'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All'), 'Expand All' => $this->l('Expand All'),
'Check All' => $this->l('Check All'), 'Check All' => $this->l('Check All'),
'Uncheck All' => $this->l('Uncheck All') 'Uncheck All' => $this->l('Uncheck All')
); );
$html .= '<div class="margin-form">'.Helper::renderAdminCategorieTree($trads, $indexedCategories).'</div>'; $html .= '<div class="margin-form">'.Helper::renderAdminCategorieTree($trads, $indexedCategories).'</div>';
@ -500,7 +500,7 @@ class Loyalty extends Module
return; return;
} }
include_once(dirname(__FILE__).'/LoyaltyModule.php'); include_once(dirname(__FILE__).'/LoyaltyModule.php');
global $smarty; global $smarty;
$product = new Product((int)Tools::getValue('id_product')); $product = new Product((int)Tools::getValue('id_product'));
@ -546,12 +546,12 @@ class Loyalty extends Module
} }
return $this->display(__FILE__, 'my-account.tpl'); return $this->display(__FILE__, 'my-account.tpl');
} }
public function hookMyAccountBlock($params) public function hookMyAccountBlock($params)
{ {
return $this->hookCustomerAccount($params); return $this->hookCustomerAccount($params);
} }
/* Catch product returns and substract loyalty discounts */ /* Catch product returns and substract loyalty discounts */
public function hookOrderReturn($params) public function hookOrderReturn($params)
{ {
@ -607,14 +607,14 @@ class Loyalty extends Module
{ {
$discount_value = LoyaltyModule::getCartDiscountValue($params['cart']); $discount_value = LoyaltyModule::getCartDiscountValue($params['cart']);
$smarty->assign(array( $smarty->assign(array(
'discount_value' => $discount_value, 'discount_value' => $discount_value,
'voucher' => $discount_value, 'voucher' => $discount_value,
'guest_checkout' => (int)Configuration::get('PS_GUEST_CHECKOUT_ENABLED') 'guest_checkout' => (int)Configuration::get('PS_GUEST_CHECKOUT_ENABLED')
)); ));
} else { } else {
$smarty->assign(array('discount_value' => 0)); $smarty->assign(array('discount_value' => 0));
} }
return $this->display(__FILE__, 'shopping-cart.tpl'); return $this->display(__FILE__, 'shopping-cart.tpl');
} }
@ -623,7 +623,7 @@ class Loyalty extends Module
{ {
include_once(dirname(__FILE__).'/LoyaltyStateModule.php'); include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
include_once(dirname(__FILE__).'/LoyaltyModule.php'); include_once(dirname(__FILE__).'/LoyaltyModule.php');
if (!Validate::isLoadedObject($params['customer']) OR !Validate::isLoadedObject($params['order'])) if (!Validate::isLoadedObject($params['customer']) OR !Validate::isLoadedObject($params['order']))
die(Tools::displayError('Missing parameters')); die(Tools::displayError('Missing parameters'));
@ -647,7 +647,7 @@ class Loyalty extends Module
{ {
include_once(dirname(__FILE__).'/LoyaltyStateModule.php'); include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
include_once(dirname(__FILE__).'/LoyaltyModule.php'); include_once(dirname(__FILE__).'/LoyaltyModule.php');
if (!Validate::isLoadedObject($params['newOrderStatus'])) if (!Validate::isLoadedObject($params['newOrderStatus']))
die(Tools::displayError('Missing parameters')); die(Tools::displayError('Missing parameters'));
$newOrder = $params['newOrderStatus']; $newOrder = $params['newOrderStatus'];
@ -666,7 +666,7 @@ class Loyalty extends Module
if ((int)Configuration::get('PS_LOYALTY_NONE_AWARD') AND $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) if ((int)Configuration::get('PS_LOYALTY_NONE_AWARD') AND $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId())
return true; return true;
if ($newOrder->id == $this->loyaltyStateValidation->id_order_state) if ($newOrder->id == $this->loyaltyStateValidation->id_order_state && $loyalty->id_loyalty_state != LoyaltyStateModule::getCancelId())
{ {
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId(); $loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
if ((float)($loyalty->discount_value) == 0) { if ((float)($loyalty->discount_value) == 0) {
@ -688,7 +688,7 @@ class Loyalty extends Module
{ {
include_once(dirname(__FILE__).'/LoyaltyModule.php'); include_once(dirname(__FILE__).'/LoyaltyModule.php');
include_once(dirname(__FILE__).'/LoyaltyStateModule.php'); include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
$customer = new Customer((int)$params['id_customer']); $customer = new Customer((int)$params['id_customer']);
if ($customer AND !Validate::isLoadedObject($customer)) if ($customer AND !Validate::isLoadedObject($customer))
die(Tools::displayError('Incorrect object Customer.')); die(Tools::displayError('Incorrect object Customer.'));
@ -704,11 +704,11 @@ class Loyalty extends Module
$html = ' $html = '
<br /><h2>'.$this->l('Loyalty progam').' ('.Tools::displayPrice($discount_value, (int)Configuration::get('PS_CURRENCY_DEFAULT')).')</h2>'; <br /><h2>'.$this->l('Loyalty progam').' ('.Tools::displayPrice($discount_value, (int)Configuration::get('PS_CURRENCY_DEFAULT')).')</h2>';
if (!$details || empty($details)) { if (!$details || empty($details)) {
return $html.' '.$this->l('This customer has no points'); return $html.' '.$this->l('This customer has no points');
} }
$html .= ' $html .= '
<table cellspacing="0" cellpadding="0" class="table"> <table cellspacing="0" cellpadding="0" class="table">
<tr style="background-color:#F5E9CF; padding: 0.3em 0.1em;"> <tr style="background-color:#F5E9CF; padding: 0.3em 0.1em;">
@ -738,14 +738,14 @@ class Loyalty extends Module
return $html; return $html;
} }
public function hookCancelProduct($params) public function hookCancelProduct($params)
{ {
include_once(dirname(__FILE__).'/LoyaltyStateModule.php'); include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
include_once(dirname(__FILE__).'/LoyaltyModule.php'); include_once(dirname(__FILE__).'/LoyaltyModule.php');
if (!Validate::isLoadedObject($params['order']) if (!Validate::isLoadedObject($params['order'])
OR !Validate::isLoadedObject($orderDetail = new OrderDetail((int)($params['id_order_detail']))) OR !Validate::isLoadedObject($orderDetail = new OrderDetail((int)($params['id_order_detail'])))
OR !Validate::isLoadedObject($loyalty = new LoyaltyModule((int)(LoyaltyModule::getByOrderId((int)($params['order']->id))))) OR !Validate::isLoadedObject($loyalty = new LoyaltyModule((int)(LoyaltyModule::getByOrderId((int)($params['order']->id)))))
) { ) {
return false; return false;
@ -770,7 +770,7 @@ class Loyalty extends Module
return; return;
} }
public function getL($key) public function getL($key)
{ {
$translations = array( $translations = array(