* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 9844 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
/*
* TODO:
*
* - 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()
{
$this->name = 'loyalty';
$this->tab = 'pricing_promotion';
$this->version = '1.8';
$this->author = 'PrestaShop';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Customer loyalty and rewards');
$this->description = $this->l('Provide a loyalty program to your customers.');
$this->confirmUninstall = $this->l('Are you sure you want to delete all loyalty points and customer history?');
}
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());
$this->loyaltyStateCancel = new LoyaltyStateModule(LoyaltyStateModule::getCancelId());
$this->loyaltyStateConvert = new LoyaltyStateModule(LoyaltyStateModule::getConvertId());
$this->loyaltyStateNoneAward = new LoyaltyStateModule(LoyaltyStateModule::getNoneAwardId());
}
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_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)
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)
$category_config .= (int)$category['id_category'].',';
$category_config = rtrim($category_config, ',');
Configuration::updateValue('PS_LOYALTY_VOUCHER_CATEGORY', $category_config);
/* This hook is optional */
$this->registerHook('myAccountBlock');
if (!LoyaltyStateModule::insertDefaultData())
return false;
return true;
}
function installDB()
{
Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'loyalty` (
`id_loyalty` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_loyalty_state` INT UNSIGNED NOT NULL DEFAULT 1,
`id_customer` INT UNSIGNED NOT NULL,
`id_order` INT UNSIGNED DEFAULT NULL,
`id_discount` INT UNSIGNED DEFAULT NULL,
`discount_value` DECIMAL NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL,
`date_upd` DATETIME NOT NULL,
PRIMARY KEY (`id_loyalty`),
INDEX index_loyalty_loyalty_state (`id_loyalty_state`),
INDEX index_loyalty_order (`id_order`),
INDEX index_loyalty_discount (`id_discount`),
INDEX index_loyalty_customer (`id_customer`)
) DEFAULT CHARSET=utf8 ;');
Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'loyalty_history` (
`id_loyalty_history` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_loyalty` INT UNSIGNED DEFAULT NULL,
`id_loyalty_state` INT UNSIGNED NOT NULL DEFAULT 1,
`discount_value` DECIMAL NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL,
PRIMARY KEY (`id_loyalty_history`),
INDEX `index_loyalty_history_loyalty` (`id_loyalty`),
INDEX `index_loyalty_history_loyalty_state` (`id_loyalty_state`)
) DEFAULT CHARSET=utf8 ;');
Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'loyalty_state` (
`id_loyalty_state` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_order_state` INT UNSIGNED DEFAULT NULL,
PRIMARY KEY (`id_loyalty_state`),
INDEX index_loyalty_state_order_state (`id_order_state`)
) DEFAULT CHARSET=utf8 ;');
Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'loyalty_state_lang` (
`id_loyalty_state` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_lang` INT UNSIGNED NOT NULL,
`name` varchar(64) NOT NULL,
UNIQUE KEY `index_unique_loyalty_state_lang` (`id_loyalty_state`,`id_lang`)
) DEFAULT CHARSET=utf8 ;');
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')
) {
return false;
}
return true;
}
function uninstallDB()
{
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'loyalty`;');
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'loyalty_state`;');
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'loyalty_state_lang`;');
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'loyalty_history`;');
return true;
}
private function _postProcess()
{
if (Tools::isSubmit('submitLoyalty'))
{
$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');
if (!sizeof($this->_errors))
{
Configuration::updateValue('PS_LOYALTY_VOUCHER_CATEGORY', $this->voucherCategories(Tools::getValue('categoryBox')));
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)
{
$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']));
$this->loyaltyStateValidation->name[(int)($language['id_lang'])] = Tools::getValue('validation_loyalty_state_'.(int)($language['id_lang']));
$this->loyaltyStateCancel->name[(int)($language['id_lang'])] = Tools::getValue('cancel_loyalty_state_'.(int)($language['id_lang']));
$this->loyaltyStateConvert->name[(int)($language['id_lang'])] = Tools::getValue('convert_loyalty_state_'.(int)($language['id_lang']));
$this->loyaltyStateNoneAward->name[(int)($language['id_lang'])] = Tools::getValue('none_award_loyalty_state_'.(int)($language['id_lang']));
}
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();
echo $this->displayConfirmation($this->l('Settings updated.'));
}
else
{
$errors = '';
foreach ($this->_errors AS $error)
$errors .= $error.'
';
echo $this->displayError($errors);
}
}
if (Tools::isSubmit('submitUpdateLoyaltyOrders'))
{
$count_orders = $this->updateLoyaltyOrders();
echo $this->displayConfirmation($count_orders.' '.$this->l('Loyalty Orders updated.'));
}
}
private function voucherCategories($categories)
{
$cat = '';
if ($categories)
foreach ($categories AS $category)
$cat .= $category.',';
return rtrim($cat, ',');
}
public function getContent()
{
global $cookie;
$this->instanceDefaultStates();
$this->_postProcess();
$categories = Category::getCategories((int)($cookie->id_lang));
$order_states = OrderState::getOrderStates((int)$cookie->id_lang);
$currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT')));
$defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
$languages = Language::getLanguages(false);
$languageIds = 'voucher_details¤default_loyalty_state¤none_award_loyalty_state¤convert_loyalty_state¤validation_loyalty_state¤cancel_loyalty_state';
$html = '
'.$this->l('Loyalty Program').'
';
$html .='';
return $html;
}
public function updateLoyaltyOrders()
{
include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
include_once(dirname(__FILE__).'/LoyaltyModule.php');
$count_orders = 0;
foreach (Db::getInstance()->ExecuteS('
SELECT lo.`id_order`, oh.`id_order_state`
FROM `'._DB_PREFIX_.'loyalty` lo
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lo.`id_order`)
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lo.`id_order` GROUP BY moh.`id_order`)
AND oh.`id_order_state` = 4 AND lo.`id_loyalty_state` NOT IN (2,4)
') as $order) {
if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId((int)$order['id_order'])))) {
continue;
}
if ((int)Configuration::get('PS_LOYALTY_NONE_AWARD') AND $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) {
continue;
}
if ((int)$order['id_order_state'] == $this->loyaltyStateValidation->id_order_state)
{
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
if ((float)($loyalty->discount_value) == 0) {
$loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($order);
}
}
$loyalty->save();
$count_orders++;
}
return $count_orders;
}
public static function recurseCategoryForInclude($id_obj, $indexedCategories, $categories, $current, $id_category = 1, $id_category_default = NULL, $has_suite = array())
{
global $done;
static $irow;
$html = '';
if (!isset($done[$current['infos']['id_parent']]))
$done[$current['infos']['id_parent']] = 0;
$done[$current['infos']['id_parent']] += 1;
$todo = sizeof($categories[$current['infos']['id_parent']]);
$doneC = $done[$current['infos']['id_parent']];
$level = $current['infos']['level_depth'] + 1;
$html .= '
|
'.$id_category.'
|
';
for ($i = 2; $i < $level; $i++)
$html .= '';
$html .= '
|
';
if ($level > 1)
$has_suite[] = ($todo == $doneC ? 0 : 1);
if (isset($categories[$id_category]))
foreach ($categories[$id_category] AS $key => $row)
if ($key != 'infos')
$html .= self::recurseCategoryForInclude($id_obj, $indexedCategories, $categories, $categories[$id_category][$key], $key, $id_category_default, $has_suite);
return $html;
}
/* Hook display on product detail */
public function hookExtraRight($params)
{
global $site_version;
// if ($site_version == 'es') {
// return;
// }
include_once(dirname(__FILE__).'/LoyaltyModule.php');
global $smarty;
$product = new Product((int)Tools::getValue('id_product'));
if (Validate::isLoadedObject($product))
{
if (Validate::isLoadedObject($params['cart']))
{
$discountValueBefore = (LoyaltyModule::getCartDiscountValue($params['cart']));
$discountValueAfter = (LoyaltyModule::getCartDiscountValue($params['cart'], $product));
$discountValue = ($discountValueAfter - $discountValueBefore);
}
else
{
if (!(int)(Configuration::get('PS_LOYALTY_NONE_AWARD')) AND Product::isDiscounted((int)$product->id))
{
$discountValue = 0;
$smarty->assign('no_pts_discounted', 1);
} else {
$discountValue = (float)(LoyaltyModule::getDiscountValueByPrice($product->getPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? false : true, (int)($product->getIdProductAttributeMostExpensive()))));
}
$discountValueAfter = $discountValue;
$discountValueBefore = 0;
}
$smarty->assign(array(
'discountValue' => $discountValue,
'total_discounts' => $discountValueAfter,
'discount_percent' => Configuration::get('PS_LOYALTY_PERCENT_VALUE'),
'discounts_in_cart' => $discountValueBefore
));
return $this->display(__FILE__, 'product.tpl');
}
return false;
}
/* Hook display on customer account page */
public function hookCustomerAccount($params)
{
global $site_version, $cookie;
// if ($site_version == 'es' || $cookie->id_lang == 3) {
// return;
// }
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)
{
include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
include_once(dirname(__FILE__).'/LoyaltyModule.php');
$totalPrice = 0;
$details = OrderReturn::getOrdersReturnDetail((int)($params['orderReturn']->id));
foreach ($details AS $detail)
{
$orderDetail = Db::getInstance()->getRow('
SELECT product_price * (1 + (tax_rate / 100)) price, product_quantity_discount, reduction_percent, id_order,
ROUND(((od.`product_price` * (1 - od.`reduction_percent` / 100) - od.`reduction_amount`) * (1 - d.`group_reduction` / 100) * (1 + d.`tax_rate` / 100)), 6) AS `price_calc`
FROM '._DB_PREFIX_.'order_detail od
WHERE id_order_detail = '.(int)($detail['id_order_detail']));
if ($orderDetail['price_calc']>0) {
$product_price = $orderDetail['price_calc'];
} elseif ($orderDetail['product_quantity_discount']>0) {
$product_price = $orderDetail['product_quantity_discount'];
} elseif ($orderDetail['reduction_percent']>0) {
$reduction = $price * ($orderDetail['reduction_percent'] / 100);
$product_price = $price - $reduction;
}
$totalPrice += ($product_price * $detail['product_quantity']);
}
$id_loyalty = LoyaltyModule::getByOrderId((int)$params['orderReturn']->id_order);
if ($id_loyalty) {
$loyalty = new LoyaltyModule((int)$id_loyalty);
$totalPrice = LoyaltyModule::getDiscountValueByPrice($totalPrice);;
$loyalty->discount_value = $loyalty->discount_value - number_format($totalPrice, 2, '.', '');
if ($loyalty->discount_value<=0) {
$loyalty->discount_value = 0;
$loyalty->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
}
$loyalty->id_order = (int)$params['orderReturn']->id_order;
$loyalty->id_customer = (int)$params['orderReturn']->id_customer;
$loyalty->save();
}
}
/* Hook display on shopping cart summary */
public function hookShoppingCart($params)
{
global $site_version, $smarty;
// if ($site_version == 'es') {
// return;
// }
include_once(dirname(__FILE__).'/LoyaltyModule.php');
if (Validate::isLoadedObject($params['cart']))
{
$discount_value = LoyaltyModule::getCartDiscountValue($params['cart']);
$smarty->assign(array(
'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');
}
/* Hook called when a new order is created */
public function hookNewOrder($params)
{
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'));
global $site_version;
// if ($site_version == 'es' || (int)$params['order']->id_lang == 3) {
// return true;
// }
$loyalty = new LoyaltyModule();
$loyalty->id_customer = (int)$params['customer']->id;
$loyalty->id_order = (int)$params['order']->id;
$loyalty->discount_value = (float)LoyaltyModule::getOrderDiscountValue($params['order']);
if (!Configuration::get('PS_LOYALTY_NONE_AWARD') AND $loyalty->discount_value == 0)
$loyalty->id_loyalty_state = LoyaltyStateModule::getNoneAwardId();
else
$loyalty->id_loyalty_state = LoyaltyStateModule::getDefaultId();
return $loyalty->save();
}
/* Hook called when an order change its status */
public function hookUpdateOrderStatus($params)
{
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'];
$order = new Order((int)($params['id_order']));
// if ($order->id_lang == 3) {
// return true;
// }
if ($order AND !Validate::isLoadedObject($order))
die(Tools::displayError('Incorrect object Order.'));
$this->instanceDefaultStates();
if ($newOrder->id == $this->loyaltyStateValidation->id_order_state OR $newOrder->id == $this->loyaltyStateCancel->id_order_state)
{
if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId($order->id))))
return false;
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 && $loyalty->id_loyalty_state != LoyaltyStateModule::getCancelId())
{
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
if ((float)($loyalty->discount_value) == 0) {
$loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($order);
}
}
elseif ($newOrder->id == $this->loyaltyStateCancel->id_order_state)
{
$loyalty->id_loyalty_state = LoyaltyStateModule::getCancelId();
$loyalty->discount_value = 0;
}
return $loyalty->save();
}
return true;
}
/* Hook display in tab AdminCustomers on BO */
public function hookAdminCustomers($params)
{
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.'));
$details = LoyaltyModule::getAllByIdCustomer((int)$params['id_customer'], (int)$params['cookie']->id_lang);
$valid_orders = LoyaltyModule::getAllByIdCustomerCustom((int)$params['id_customer'], (int)$params['cookie']->id_lang, true, false, $nb = 10, $page = 1, false);
if (!empty($valid_orders)) {
$discount_value = LoyaltyModule::getVoucherValueByPercentOfOrder($valid_orders, (int)Configuration::get('PS_CURRENCY_DEFAULT'));
} else {
$discount_value = 0;
}
$html = '
'.$this->l('Loyalty progam').' ('.Tools::displayPrice($discount_value, (int)Configuration::get('PS_CURRENCY_DEFAULT')).')
';
if (!$details || empty($details)) {
return $html.' '.$this->l('This customer has no points');
}
$html .= '
'.$this->l('Order').' |
'.$this->l('Date').' |
'.$this->l('Discount').' |
'.$this->l('Discount Status').' |
';
foreach ($details AS $key => $loyalty)
{
$html.= '
'.((int)$loyalty['id'] > 0 ? ''.$this->l('#').sprintf('%06d', $loyalty['id']).'' : '--').' |
'.Tools::displayDate($loyalty['date'], (int)($params['cookie']->id_lang)).' |
'.Tools::displayPrice((float)$loyalty['discount_value'],(int)Configuration::get('PS_CURRENCY_DEFAULT')).' |
'.$loyalty['state'].' |
';
}
$html.= '
|
'.$this->l('Voucher value:').' |
'.Tools::displayPrice($discount_value, new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'))).' |
|
';
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'])))
OR !Validate::isLoadedObject($loyalty = new LoyaltyModule((int)(LoyaltyModule::getByOrderId((int)($params['order']->id)))))
) {
return false;
}
if ($orderDetail->product_quantity_discount>0) {
$product_price = $orderDetail->product_quantity_discount;
} elseif ($orderDetail->reduction_percent>0) {
$reduction = ($orderDetail->product_price * (1 + $orderDetail->tax_rate / 100)) * ($orderDetail->reduction_percent / 100);
$product_price = ($orderDetail->product_price * (1 + $orderDetail->tax_rate / 100)) - $reduction;
}
$price = (float)($product_price * $orderDetail->product_quantity_refunded);
$price = LoyaltyModule::getDiscountValueByPrice($price);
$price = $loyalty->discount_value - number_format($price, 2, '.', '');
if ($price>0) {
$loyalty->discount_value = $price;
} else {
$loyalty->discount_value = 0;
$loyalty->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
}
$loyalty->save();
return;
}
public function getL($key)
{
$translations = array(
'Awaiting validation' => $this->l('Awaiting validation'),
'Available' => $this->l('Available'),
'Cancelled' => $this->l('Cancelled'),
'Already converted' => $this->l('Already converted'),
'Unavailable on discounts' => $this->l('Unavailable on discounts'),
'Not available on discounts.' => $this->l('Not available on discounts.'));
return (array_key_exists($key, $translations)) ? $translations[$key] : $key;
}
}