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