diff --git a/modules/loyalty/controllers/front/default.php b/modules/loyalty/controllers/front/default.php
index 80320dfdd..15f31daa1 100644
--- a/modules/loyalty/controllers/front/default.php
+++ b/modules/loyalty/controllers/front/default.php
@@ -40,7 +40,7 @@ class LoyaltyDefaultModuleFrontController extends ModuleFrontController
include_once($this->module->getLocalPath().'LoyaltyModule.php');
include_once($this->module->getLocalPath().'LoyaltyStateModule.php');
-
+
// Declare smarty function to render pagination link
smartyRegisterFunction($this->context->smarty, 'function', 'summarypaginationlink', array('LoyaltyDefaultModuleFrontController', 'getSummaryPaginationLink'));
}
@@ -53,69 +53,69 @@ class LoyaltyDefaultModuleFrontController extends ModuleFrontController
if (Tools::getValue('process') == 'transformpoints')
$this->processTransformPoints();
}
-
+
/**
* Transform loyalty point to a voucher
*/
public function processTransformPoints()
{
- $customerPoints = (int)LoyaltyModule::getPointsByCustomer((int)$this->context->customer->id);
- if ($customerPoints > 0)
+ $customer_points = (int)LoyaltyModule::getPointsByCustomer((int)$this->context->customer->id);
+ if ($customer_points > 0)
{
/* Generate a voucher code */
- $voucherCode = null;
+ $voucher_code = null;
do
- $voucherCode = 'FID'.rand(1000, 100000);
- while (CartRule::cartRuleExists($voucherCode));
-
+ $voucher_code = 'FID'.rand(1000, 100000);
+ while (CartRule::cartRuleExists($voucher_code));
+
// Voucher creation and affectation to the customer
- $cartRule = new CartRule();
- $cartRule->code = $voucherCode;
- $cartRule->id_customer = (int)$this->context->customer->id;
- $cartRule->reduction_currency = (int)$this->context->currency->id;
- $cartRule->reduction_amount = LoyaltyModule::getVoucherValue((int)$customerPoints);
- $cartRule->quantity = 1;
- $cartRule->quantity_per_user = 1;
-
+ $cart_rule = new CartRule();
+ $cart_rule->code = $voucher_code;
+ $cart_rule->id_customer = (int)$this->context->customer->id;
+ $cart_rule->reduction_currency = (int)$this->context->currency->id;
+ $cart_rule->reduction_amount = LoyaltyModule::getVoucherValue((int)$customer_points);
+ $cart_rule->quantity = 1;
+ $cart_rule->quantity_per_user = 1;
+
// If merchandise returns are allowed, the voucher musn't be usable before this max return date
- $dateFrom = Db::getInstance()->getValue('
+ $date_from = Db::getInstance()->getValue('
SELECT UNIX_TIMESTAMP(date_add) n
FROM '._DB_PREFIX_.'loyalty
WHERE id_cart_rule = 0 AND id_customer = '.(int)$this->context->cookie->id_customer.'
ORDER BY date_add DESC');
-
+
if (Configuration::get('PS_ORDER_RETURN'))
- $dateFrom += 60 * 60 * 24 * (int)Configuration::get('PS_ORDER_RETURN_NB_DAYS');
-
- $cartRule->date_from = date('Y-m-d H:i:s', $dateFrom);
- $cartRule->date_to = date('Y-m-d H:i:s', strtotime($cartRule->date_from.' +1 year'));
-
- $cartRule->minimum_amount = (float)Configuration::get('PS_LOYALTY_MINIMAL');
- $cartRule->active = 1;
-
+ $date_from += 60 * 60 * 24 * (int)Configuration::get('PS_ORDER_RETURN_NB_DAYS');
+
+ $cart_rule->date_from = date('Y-m-d H:i:s', $date_from);
+ $cart_rule->date_to = date('Y-m-d H:i:s', strtotime($cart_rule->date_from.' +1 year'));
+
+ $cart_rule->minimum_amount = (float)Configuration::get('PS_LOYALTY_MINIMAL');
+ $cart_rule->active = 1;
+
$categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
if ($categories != '' && $categories != 0)
$categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
else
die (Tools::displayError());
-
+
$languages = Language::getLanguages(true);
$default_text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)Configuration::get('PS_LANG_DEFAULT'));
-
+
foreach ($languages as $language)
{
$text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)$language['id_lang']);
- $cartRule->name[(int)$language['id_lang']] = $text ? strval($text) : strval($default_text);
+ $cart_rule->name[(int)$language['id_lang']] = $text ? strval($text) : strval($default_text);
}
-
+
if (is_array($categories) && count($categories))
- $cartRule->add(true, false, $categories);
+ $cart_rule->add(true, false, $categories);
else
- $cartRule->add();
-
+ $cart_rule->add();
+
// Register order(s) which contributed to create this voucher
- LoyaltyModule::registerDiscount($cartRule);
-
+ LoyaltyModule::registerDiscount($cart_rule);
+
Tools::redirect($this->context->link->getModuleLink('loyalty', 'default', array('process' => 'summary')));
}
}
@@ -127,11 +127,11 @@ class LoyaltyDefaultModuleFrontController extends ModuleFrontController
{
parent::initContent();
$this->context->controller->addJqueryPlugin(array('dimensions', 'cluetip'));
-
+
if (Tools::getValue('process') == 'summary')
$this->assignSummaryExecution();
}
-
+
/**
* Render pagination link for summary
*
@@ -144,12 +144,12 @@ class LoyaltyDefaultModuleFrontController extends ModuleFrontController
$p = 1;
else
$p = $params['p'];
-
+
if (!isset($params['n']))
$n = 10;
else
$n = $params['n'];
-
+
return Context::getContext()->link->getModuleLink(
'loyalty',
'default',
@@ -160,66 +160,71 @@ class LoyaltyDefaultModuleFrontController extends ModuleFrontController
)
);
}
-
+
/**
* Assign summary template
*/
public function assignSummaryExecution()
{
- $customerPoints = (int)(LoyaltyModule::getPointsByCustomer((int)$this->context->customer->id));
- $orders = LoyaltyModule::getAllByIdCustomer((int)$this->context->customer->id, (int)$this->context->lang->id);
- $displayorders = LoyaltyModule::getAllByIdCustomer((int)$this->context->customer->id, (int)$this->context->lang->id, false, true, ((int)(Tools::getValue('n')) > 0 ? (int)(Tools::getValue('n')) : 10), ((int)(Tools::getValue('p')) > 0 ? (int)(Tools::getValue('p')) : 1));
+ $customer_points = (int)LoyaltyModule::getPointsByCustomer((int)$this->context->customer->id);
+ $orders = LoyaltyModule::getAllByIdCustomer((int)$this->context->customer->id, (int)$this->context->language->id);
+ $displayorders = LoyaltyModule::getAllByIdCustomer(
+ (int)$this->context->customer->id,
+ (int)$this->context->language->id, false, true,
+ ((int)Tools::getValue('n') > 0 ? (int)Tools::getValue('n') : 10),
+ ((int)Tools::getValue('p') > 0 ? (int)Tools::getValue('p') : 1)
+ );
$this->context->smarty->assign(array(
'orders' => $orders,
'displayorders' => $displayorders,
- 'totalPoints' => (int)$customerPoints,
- 'voucher' => LoyaltyModule::getVoucherValue($customerPoints, (int)$this->context->currency->id),
+ 'totalPoints' => (int)$customer_points,
+ 'voucher' => LoyaltyModule::getVoucherValue($customer_points, (int)$this->context->currency->id),
'validation_id' => LoyaltyStateModule::getValidationId(),
- 'transformation_allowed' => $customerPoints > 0,
- 'page' => ((int)(Tools::getValue('p')) > 0 ? (int)(Tools::getValue('p')) : 1),
- 'nbpagination' => ((int)(Tools::getValue('n') > 0) ? (int)(Tools::getValue('n')) : 10),
+ 'transformation_allowed' => $customer_points > 0,
+ 'page' => ((int)Tools::getValue('p') > 0 ? (int)Tools::getValue('p') : 1),
+ 'nbpagination' => ((int)Tools::getValue('n') > 0 ? (int)Tools::getValue('n') : 10),
'nArray' => array(10, 20, 50),
- 'max_page' => floor(sizeof($orders) / ((int)(Tools::getValue('n') > 0) ? (int)(Tools::getValue('n')) : 10))
+ 'max_page' => floor(count($orders) / ((int)Tools::getValue('n') > 0 ? (int)Tools::getValue('n') : 10))
));
-
+
/* Discounts */
- $nbDiscounts = 0;
+ $nb_discounts = 0;
$discounts = array();
if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int)$this->context->customer->id))
{
- $nbDiscounts = count($ids_discount);
+ $nb_discounts = count($ids_discount);
foreach ($ids_discount as $key => $discount)
{
$discounts[$key] = new CartRule((int)$discount['id_cart_rule'], (int)$this->context->cookie->id_lang);
$discounts[$key]->orders = LoyaltyModule::getOrdersByIdDiscount((int)$discount['id_cart_rule']);
}
}
-
- $allCategories = Category::getSimpleCategories((int)($this->context->cookie->id_lang));
- $voucherCategories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
- if ($voucherCategories != '' && $voucherCategories != 0)
- $voucherCategories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
+
+ $all_categories = Category::getSimpleCategories((int)$this->context->cookie->id_lang);
+ $voucher_categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
+ if ($voucher_categories != '' && $voucher_categories != 0)
+ $voucher_categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
else
die(Tools::displayError());
-
- if (count($voucherCategories) == count($allCategories))
- $categoriesNames = null;
+
+ if (count($voucher_categories) == count($all_categories))
+ $categories_names = null;
else
{
- $categoriesNames = array();
- foreach ($allCategories AS $k => $allCategory)
- if (in_array($allCategory['id_category'], $voucherCategories))
- $categoriesNames[$allCategory['id_category']] = trim($allCategory['name']);
- if (!empty($categoriesNames))
- $categoriesNames = Tools::truncate(implode(', ', $categoriesNames), 100).'.';
+ $categories_names = array();
+ foreach ($all_categories as $k => $all_category)
+ if (in_array($all_category['id_category'], $voucher_categories))
+ $categories_names[$all_category['id_category']] = trim($all_category['name']);
+ if (!empty($categories_names))
+ $categories_names = Tools::truncate(implode(', ', $categories_names), 100).'.';
else
- $categoriesNames = null;
+ $categories_names = null;
}
$this->context->smarty->assign(array(
- 'nbDiscounts' => (int)$nbDiscounts,
+ 'nbDiscounts' => (int)$nb_discounts,
'discounts' => $discounts,
'minimalLoyalty' => (float)Configuration::get('PS_LOYALTY_MINIMAL'),
- 'categories' => $categoriesNames));
+ 'categories' => $categories_names));
$this->setTemplate('loyalty.tpl');
}
diff --git a/modules/loyalty/loyalty.php b/modules/loyalty/loyalty.php
index 219e1da2a..749fba646 100644
--- a/modules/loyalty/loyalty.php
+++ b/modules/loyalty/loyalty.php
@@ -37,7 +37,7 @@ if (!defined('_PS_VERSION_'))
class Loyalty extends Module
{
- function __construct()
+ public function __construct()
{
$this->name = 'loyalty';
$this->tab = 'pricing_promotion';
@@ -64,27 +64,27 @@ class Loyalty extends Module
$this->loyaltyStateNoneAward = new LoyaltyStateModule(LoyaltyStateModule::getNoneAwardId());
}
- function install()
+ public function install()
{
include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
-
- 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('shoppingCart')
- OR !$this->registerHook('orderReturn') OR !$this->registerHook('cancelProduct') OR !$this->registerHook('customerAccount')
- OR !Configuration::updateValue('PS_LOYALTY_POINT_VALUE', '0.20') OR !Configuration::updateValue('PS_LOYALTY_MINIMAL', 0)
- OR !Configuration::updateValue('PS_LOYALTY_POINT_RATE', '10') OR !Configuration::updateValue('PS_LOYALTY_NONE_AWARD', '1'))
+
+ if (!parent::install() || !$this->installDB() || !$this->registerHook('extraRight') || !$this->registerHook('updateOrderStatus')
+ || !$this->registerHook('newOrder') || !$this->registerHook('adminCustomers') || !$this->registerHook('shoppingCart')
+ || !$this->registerHook('orderReturn') || !$this->registerHook('cancelProduct') || !$this->registerHook('customerAccount')
+ || !Configuration::updateValue('PS_LOYALTY_POINT_VALUE', '0.20') || !Configuration::updateValue('PS_LOYALTY_MINIMAL', 0)
+ || !Configuration::updateValue('PS_LOYALTY_POINT_RATE', '10') || !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)
+ foreach (Language::getLanguages() as $language)
if (isset($defaultTranslations[$language['iso_code']]))
$conf[(int)$language['id_lang']] = $defaultTranslations[$language['iso_code']];
Configuration::updateValue('PS_LOYALTY_VOUCHER_DETAILS', $conf);
$category_config = '';
$categories = Category::getSimpleCategories((int)(Configuration::get('PS_LANG_DEFAULT')));
- foreach ($categories AS $category)
+ foreach ($categories as $category)
$category_config .= (int)$category['id_category'].',';
$category_config = rtrim($category_config, ',');
Configuration::updateValue('PS_LOYALTY_VOUCHER_CATEGORY', $category_config);
@@ -96,7 +96,7 @@ class Loyalty extends Module
return true;
}
- function installDB()
+ public function installDB()
{
Db::getInstance()->execute('
CREATE TABLE `'._DB_PREFIX_.'loyalty` (
@@ -146,16 +146,16 @@ class Loyalty extends Module
return true;
}
- function uninstall()
+ public function uninstall()
{
- if (!parent::uninstall() OR !$this->uninstallDB() OR !Configuration::deleteByName('PS_LOYALTY_POINT_VALUE') OR !Configuration::deleteByName('PS_LOYALTY_POINT_RATE')
- 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() || !$this->uninstallDB() || !Configuration::deleteByName('PS_LOYALTY_POINT_VALUE') || !Configuration::deleteByName('PS_LOYALTY_POINT_RATE')
+ || !Configuration::deleteByName('PS_LOYALTY_NONE_AWARD') || !Configuration::deleteByName('PS_LOYALTY_MINIMAL') || !Configuration::deleteByName('PS_LOYALTY_VOUCHER_CATEGORY')
+ || !Configuration::deleteByName('PS_LOYALTY_VOUCHER_DETAILS'))
return false;
return true;
}
- function uninstallDB()
+ public function uninstallDB()
{
Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'loyalty`;');
Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'loyalty_state`;');
@@ -173,9 +173,9 @@ class Loyalty extends Module
$languages = Language::getLanguages();
$this->_errors = array();
- if (!is_array(Tools::getValue('categoryBox')) OR !sizeof(Tools::getValue('categoryBox')))
+ if (!is_array(Tools::getValue('categoryBox')) || !count(Tools::getValue('categoryBox')))
$this->_errors[] = $this->l('You must choose at least one category for voucher\'s action');
- if (!sizeof($this->_errors))
+ if (!count($this->_errors))
{
Configuration::updateValue('PS_LOYALTY_VOUCHER_CATEGORY', $this->voucherCategories(Tools::getValue('categoryBox')));
Configuration::updateValue('PS_LOYALTY_POINT_VALUE', (float)(Tools::getValue('point_value')));
@@ -187,7 +187,7 @@ class Loyalty extends Module
$this->loyaltyStateCancel->id_order_state = (int)(Tools::getValue('id_order_state_cancel'));
$arrayVoucherDetails = array();
- foreach ($languages AS $language)
+ foreach ($languages as $language)
{
$arrayVoucherDetails[(int)($language['id_lang'])] = Tools::getValue('voucher_details_'.(int)($language['id_lang']));
$this->loyaltyStateDefault->name[(int)($language['id_lang'])] = Tools::getValue('default_loyalty_state_'.(int)($language['id_lang']));
@@ -225,7 +225,7 @@ class Loyalty extends Module
else
{
$errors = '';
- foreach ($this->_errors AS $error)
+ foreach ($this->_errors as $error)
$errors .= $error.'
';
echo $this->displayError($errors);
}
@@ -237,7 +237,7 @@ class Loyalty extends Module
{
$cat = '';
if ($categories)
- foreach ($categories AS $category)
+ foreach ($categories as $category)
$cat .= $category.',';
return rtrim($cat, ',');
}
@@ -284,7 +284,7 @@ class Loyalty extends Module
| '.$this->l('Points').' | '.$this->l('Points Status').' | |||||
|---|---|---|---|---|---|---|
| '.((int)$loyalty['id'] > 0 ? ''.sprintf($this->l('#%d'), $loyalty['id']).'' : '--').' | -'.Tools::displayDate($loyalty['date'], (int)($params['cookie']->id_lang)).' | +'.((int)$loyalty['id'] > 0 ? ''.sprintf($this->l('#%d'), $loyalty['id']).'' : '--').' | +'.Tools::displayDate($loyalty['date'], (int)$params['cookie']->id_lang).' | '.((int)$loyalty['id'] > 0 ? $loyalty['total_without_shipping'] : '--').' | '.(int)$loyalty['points'].' | '.$loyalty['state'].' |
| '.$this->l('Total points available:').' | '.$points.' | -'.$this->l('Voucher value:').' '.Tools::displayPrice(LoyaltyModule::getVoucherValue((int)$points, (int)Configuration::get('PS_CURRENCY_DEFAULT')), new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'))).' | +'.$this->l('Voucher value:').' '.Tools::displayPrice( + LoyaltyModule::getVoucherValue((int)$points, (int)Configuration::get('PS_CURRENCY_DEFAULT')), + new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT')) + ).' | |||