Merge branch 'ticket-fidelite' into develop
This commit is contained in:
commit
042d42d578
@ -34,12 +34,12 @@ class LoyaltyModule extends ObjectModel
|
||||
public $id_customer;
|
||||
public $id_order;
|
||||
public $id_discount;
|
||||
public $points;
|
||||
public $discount_value;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
|
||||
protected $fieldsRequired = array('id_customer', 'points');
|
||||
protected $fieldsValidate = array('id_loyalty_state' => 'isInt', 'id_customer' => 'isInt', 'id_discount' => 'isInt', 'id_order' => 'isInt', 'points' => 'isInt');
|
||||
protected $fieldsRequired = array('id_customer', 'discount_value');
|
||||
protected $fieldsValidate = array('id_loyalty_state' => 'isInt', 'id_customer' => 'isInt', 'id_discount' => 'isInt', 'id_order' => 'isInt', 'discount_value' => 'isInt');
|
||||
|
||||
protected $table = 'loyalty';
|
||||
protected $identifier = 'id_loyalty';
|
||||
@ -51,7 +51,7 @@ class LoyaltyModule extends ObjectModel
|
||||
$fields['id_customer'] = (int)$this->id_customer;
|
||||
$fields['id_order'] = (int)$this->id_order;
|
||||
$fields['id_discount'] = (int)$this->id_discount;
|
||||
$fields['points'] = (int)$this->points;
|
||||
$fields['discount_value'] = (int)$this->discount_value;
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
return $fields;
|
||||
@ -76,14 +76,15 @@ class LoyaltyModule extends ObjectModel
|
||||
return isset($result['id_loyalty']) ? $result['id_loyalty'] : false;
|
||||
}
|
||||
|
||||
public static function getOrderNbPoints($order)
|
||||
|
||||
public static function getOrderDiscountValue($order)
|
||||
{
|
||||
if (!Validate::isLoadedObject($order))
|
||||
return false;
|
||||
return self::getCartNbPoints(new Cart((int)$order->id_cart));
|
||||
return self::getCartDiscountValue(new Cart((int)$order->id_cart));
|
||||
}
|
||||
|
||||
public static function getCartNbPoints($cart, $newProduct = NULL)
|
||||
public static function getCartDiscountValue($cart, $newProduct = NULL)
|
||||
{
|
||||
$total = 0;
|
||||
if (Validate::isLoadedObject($cart))
|
||||
@ -115,10 +116,10 @@ class LoyaltyModule extends ObjectModel
|
||||
$total -= $discount['value_real'];
|
||||
}
|
||||
|
||||
return self::getNbPointsByPrice($total);
|
||||
return self::getDiscountValueByPrice($total);
|
||||
}
|
||||
|
||||
public static function getVoucherValue($nbPoints, $id_currency = NULL)
|
||||
/*public static function getVoucherValue($nbPoints, $id_currency = NULL)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
@ -126,9 +127,24 @@ class LoyaltyModule extends ObjectModel
|
||||
$id_currency = (int)$cookie->id_currency;
|
||||
|
||||
return (int)$nbPoints * (float)Tools::convertPrice(Configuration::get('PS_LOYALTY_POINT_VALUE'), new Currency((int)$id_currency));
|
||||
}*/
|
||||
|
||||
public static function getVoucherValueByPercentOfOrder($orders, $id_currency = NULL)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if (empty($id_currency))
|
||||
$id_currency = (int)$cookie->id_currency;
|
||||
|
||||
$value = 0;
|
||||
foreach ($orders as $key => $order) {
|
||||
$value += $order['discount_value'];
|
||||
}
|
||||
|
||||
return (float)Tools::convertPrice($value, new Currency((int)$id_currency));
|
||||
}
|
||||
|
||||
public static function getNbPointsByPrice($price)
|
||||
public static function getDiscountValueByPrice($price)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
@ -139,15 +155,12 @@ class LoyaltyModule extends ObjectModel
|
||||
$price = $price / $currency->conversion_rate;
|
||||
}
|
||||
|
||||
/* Prevent division by zero */
|
||||
$points = 0;
|
||||
if ($pointRate = (float)(Configuration::get('PS_LOYALTY_POINT_RATE')))
|
||||
$points = floor(number_format($price, 2, '.', '') / $pointRate);
|
||||
$discount_value = (float)(Configuration::get('PS_LOYALTY_PERCENT_VALUE') * $price) / 100;
|
||||
|
||||
return (int)$points;
|
||||
return (float)$discount_value;
|
||||
}
|
||||
|
||||
public static function getPointsByCustomer($id_customer)
|
||||
/*public static function getPointsByCustomer($id_customer)
|
||||
{
|
||||
return
|
||||
Db::getInstance()->getValue('
|
||||
@ -161,12 +174,12 @@ class LoyaltyModule extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'loyalty` f
|
||||
WHERE f.id_customer = '.(int)($id_customer).'
|
||||
AND f.id_loyalty_state = '.(int)LoyaltyStateModule::getCancelId().' AND points < 0');
|
||||
}
|
||||
}*/
|
||||
|
||||
public static function getAllByIdCustomer($id_customer, $id_lang, $onlyValidate = false, $pagination = false, $nb = 10, $page = 1)
|
||||
{
|
||||
$query = '
|
||||
SELECT f.id_order AS id, f.date_add AS date, (o.total_paid - o.total_shipping) total_without_shipping, f.points, f.id_loyalty, f.id_loyalty_state, fsl.name state
|
||||
SELECT f.id_order AS id, f.date_add AS date, (o.total_paid - o.total_shipping) total_without_shipping, f.discount_value, f.id_loyalty, f.id_loyalty_state, fsl.name state
|
||||
FROM `'._DB_PREFIX_.'loyalty` f
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (f.id_order = o.id_order)
|
||||
LEFT JOIN `'._DB_PREFIX_.'loyalty_state_lang` fsl ON (f.id_loyalty_state = fsl.id_loyalty_state AND fsl.id_lang = '.(int)($id_lang).')
|
||||
@ -179,6 +192,27 @@ class LoyaltyModule extends ObjectModel
|
||||
return Db::getInstance()->ExecuteS($query);
|
||||
}
|
||||
|
||||
public static function getAllByIdCustomerCustom($id_customer, $id_lang, $onlyValidate = false, $pagination = false, $nb = 10, $page = 1, $percent = 1.75)
|
||||
{
|
||||
$query = '
|
||||
SELECT f.id_order AS id, f.date_add AS date,
|
||||
(o.total_paid - o.total_shipping) total_without_shipping,
|
||||
(('.$percent.' * (o.total_paid - o.total_shipping)) / 100) as reduc_value,
|
||||
f.discount_value, f.id_loyalty, f.id_loyalty_state, fsl.name state
|
||||
FROM `'._DB_PREFIX_.'loyalty` f
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (f.id_order = o.id_order)
|
||||
LEFT JOIN `'._DB_PREFIX_.'loyalty_state_lang` fsl ON (f.id_loyalty_state = fsl.id_loyalty_state AND fsl.id_lang = '.(int)($id_lang).')
|
||||
WHERE f.id_customer = '.(int)($id_customer).'
|
||||
AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId();
|
||||
if ($onlyValidate) {
|
||||
$query .= ' AND f.id_loyalty_state = '.(int)LoyaltyStateModule::getValidationId();
|
||||
}
|
||||
$query .= ' GROUP BY f.id_loyalty '.
|
||||
($pagination ? 'LIMIT '.(((int)($page) - 1) * (int)($nb)).', '.(int)($nb) : '');
|
||||
|
||||
return Db::getInstance()->ExecuteS($query);
|
||||
}
|
||||
|
||||
public static function getDiscountByIdCustomer($id_customer, $last=false)
|
||||
{
|
||||
$query = '
|
||||
@ -195,28 +229,26 @@ class LoyaltyModule extends ObjectModel
|
||||
return Db::getInstance()->ExecuteS($query);
|
||||
}
|
||||
|
||||
public static function registerDiscount($discount)
|
||||
|
||||
public static function registerDiscountCustom($discount, $orders)
|
||||
{
|
||||
if (!Validate::isLoadedObject($discount))
|
||||
die(Tools::displayError('Incorrect object Discount.'));
|
||||
$items = self::getAllByIdCustomer((int)$discount->id_customer, NULL, true);
|
||||
foreach ($items AS $item)
|
||||
foreach ($orders AS $item)
|
||||
{
|
||||
$f = new LoyaltyModule((int)$item['id_loyalty']);
|
||||
|
||||
/* Check for negative points for this order */
|
||||
$negativePoints = (int)Db::getInstance()->getValue('SELECT SUM(points) points FROM '._DB_PREFIX_.'loyalty WHERE id_order = '.(int)$f->id_order.' AND id_loyalty_state = '.(int)LoyaltyStateModule::getCancelId().' AND points < 0');
|
||||
|
||||
if ($f->points + $negativePoints <= 0)
|
||||
|
||||
if ($f->discount_value = 0) {
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
$f->id_discount = (int)$discount->id;
|
||||
$f->id_loyalty_state = (int)LoyaltyStateModule::getConvertId();
|
||||
$f->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getOrdersByIdDiscount($id_discount)
|
||||
/*public static function getOrdersByIdDiscount($id_discount)
|
||||
{
|
||||
$items = Db::getInstance()->ExecuteS('
|
||||
SELECT f.id_order AS id_order, f.points AS points, f.date_upd AS date
|
||||
@ -236,6 +268,29 @@ class LoyaltyModule extends ObjectModel
|
||||
return $items;
|
||||
}
|
||||
|
||||
return false;
|
||||
}*/
|
||||
|
||||
public static function getOrdersByIdDiscountCustom($id_discount)
|
||||
{
|
||||
$items = Db::getInstance()->ExecuteS('
|
||||
SELECT f.id_order AS id_order, f.discount_value, f.date_upd AS date,
|
||||
FROM `'._DB_PREFIX_.'loyalty` f
|
||||
WHERE f.id_discount = '.(int)($id_discount).' AND f.id_loyalty_state = '.(int)(LoyaltyStateModule::getConvertId()));
|
||||
|
||||
if (!empty($items) AND is_array($items))
|
||||
{
|
||||
foreach ($items AS $key => $item)
|
||||
{
|
||||
$order = new Order((int)$item['id_order']);
|
||||
$items[$key]['id_currency'] = (int)$order->id_currency;
|
||||
$items[$key]['id_lang'] = (int)$order->id_lang;
|
||||
$items[$key]['total_paid'] = $order->total_paid;
|
||||
$items[$key]['total_shipping'] = $order->total_shipping;
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -243,8 +298,8 @@ class LoyaltyModule extends ObjectModel
|
||||
private function historize()
|
||||
{
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'loyalty_history` (`id_loyalty`, `id_loyalty_state`, `points`, `date_add`)
|
||||
VALUES ('.(int)($this->id).', '.(int)($this->id_loyalty_state).', '.(int)($this->points).', NOW())');
|
||||
INSERT INTO `'._DB_PREFIX_.'loyalty_history` (`id_loyalty`, `id_loyalty_state`, `discount_value`, `date_add`)
|
||||
VALUES ('.(int)($this->id).', '.(int)($this->id_loyalty_state).', '.(int)($this->discount_value).', NOW())');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,10 +40,11 @@ if (!$cookie->isLogged())
|
||||
Tools::addCSS(_PS_CSS_DIR_.'jquery.cluetip.css', 'all');
|
||||
Tools::addJS(array(_PS_JS_DIR_.'jquery/jquery.dimensions.js',_PS_JS_DIR_.'jquery/jquery.cluetip.js'));
|
||||
|
||||
$customerPoints = (int)(LoyaltyModule::getPointsByCustomer((int)($cookie->id_customer)));
|
||||
|
||||
$displayorders = LoyaltyModule::getAllByIdCustomerCustom((int)($cookie->id_customer), (int)($cookie->id_lang), false, true, ((int)(Tools::getValue('n')) > 0 ? (int)(Tools::getValue('n')) : 10), ((int)(Tools::getValue('p')) > 0 ? (int)(Tools::getValue('p')) : 1));
|
||||
$orderToConvert = LoyaltyModule::getAllByIdCustomerCustom((int)($cookie->id_customer), (int)($cookie->id_lang), false, false, $nb = 10, $page = 1, true);
|
||||
$total_discount = LoyaltyModule::getVoucherValueByPercentOfOrder($orderToConvert, (int)($cookie->id_currency));
|
||||
/* transform point into voucher if needed */
|
||||
if (Tools::getValue('transform-points') == 'true' AND $customerPoints > 0)
|
||||
if (Tools::getValue('transform-points') == 'true' AND $total_discount > 0)
|
||||
{
|
||||
/* Generate a voucher code */
|
||||
$voucherCode = NULL;
|
||||
@ -56,7 +57,7 @@ if (Tools::getValue('transform-points') == 'true' AND $customerPoints > 0)
|
||||
$voucher->id_discount_type = 2; // Discount on order (amount)
|
||||
$voucher->id_customer = (int)($cookie->id_customer);
|
||||
$voucher->id_currency = (int)($cookie->id_currency);
|
||||
$voucher->value = LoyaltyModule::getVoucherValue((int)$customerPoints);
|
||||
$voucher->value = $total_discount;
|
||||
$voucher->quantity = 1;
|
||||
$voucher->quantity_per_user = 1;
|
||||
$voucher->cumulable = 1;
|
||||
@ -104,7 +105,7 @@ if (Tools::getValue('transform-points') == 'true' AND $customerPoints > 0)
|
||||
$voucher->add();
|
||||
|
||||
/* Register order(s) which contributed to create this voucher */
|
||||
LoyaltyModule::registerDiscount($voucher);
|
||||
LoyaltyModule::registerDiscountCustom($voucher, $orderToConvert);
|
||||
|
||||
Tools::redirect('modules/loyalty/loyalty-program.php');
|
||||
}
|
||||
@ -112,19 +113,19 @@ if (Tools::getValue('transform-points') == 'true' AND $customerPoints > 0)
|
||||
include(dirname(__FILE__).'/../../header.php');
|
||||
|
||||
$orders = LoyaltyModule::getAllByIdCustomer((int)($cookie->id_customer), (int)($cookie->id_lang));
|
||||
$displayorders = LoyaltyModule::getAllByIdCustomer((int)($cookie->id_customer), (int)($cookie->id_lang), false, true, ((int)(Tools::getValue('n')) > 0 ? (int)(Tools::getValue('n')) : 10), ((int)(Tools::getValue('p')) > 0 ? (int)(Tools::getValue('p')) : 1));
|
||||
|
||||
$smarty->assign(array(
|
||||
'orders' => $orders,
|
||||
'displayorders' => $displayorders,
|
||||
'pagination_link' => __PS_BASE_URI__.'modules/loyalty/loyalty-program.php',
|
||||
'totalPoints' => (int)$customerPoints,
|
||||
'voucher' => LoyaltyModule::getVoucherValue($customerPoints, (int)($cookie->id_currency)),
|
||||
'voucher' => $total_discount,
|
||||
'validation_id' => LoyaltyStateModule::getValidationId(),
|
||||
'transformation_allowed' => $customerPoints > 0,
|
||||
'transformation_allowed' => $total_discount > 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(sizeof($displayorders) / ((int)(Tools::getValue('n') > 0) ? (int)(Tools::getValue('n')) : 10))
|
||||
));
|
||||
|
||||
/* Discounts */
|
||||
|
@ -68,12 +68,22 @@ class Loyalty extends Module
|
||||
{
|
||||
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()
|
||||
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'));
|
||||
@ -105,7 +115,7 @@ class Loyalty extends Module
|
||||
`id_customer` INT UNSIGNED NOT NULL,
|
||||
`id_order` INT UNSIGNED DEFAULT NULL,
|
||||
`id_discount` INT UNSIGNED DEFAULT NULL,
|
||||
`points` INT NOT NULL DEFAULT 0,
|
||||
`discount_value` DECIMAL NOT NULL DEFAULT 0,
|
||||
`date_add` DATETIME NOT NULL,
|
||||
`date_upd` DATETIME NOT NULL,
|
||||
PRIMARY KEY (`id_loyalty`),
|
||||
@ -120,7 +130,7 @@ class Loyalty extends Module
|
||||
`id_loyalty_history` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id_loyalty` INT UNSIGNED DEFAULT NULL,
|
||||
`id_loyalty_state` INT UNSIGNED NOT NULL DEFAULT 1,
|
||||
`points` INT NOT NULL DEFAULT 0,
|
||||
`discount_value` DECIMAL NOT NULL DEFAULT 0,
|
||||
`date_add` DATETIME NOT NULL,
|
||||
PRIMARY KEY (`id_loyalty_history`),
|
||||
INDEX `index_loyalty_history_loyalty` (`id_loyalty`),
|
||||
@ -148,10 +158,15 @@ class Loyalty extends Module
|
||||
|
||||
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() 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;
|
||||
}
|
||||
|
||||
@ -178,8 +193,7 @@ class Loyalty extends Module
|
||||
if (!sizeof($this->_errors))
|
||||
{
|
||||
Configuration::updateValue('PS_LOYALTY_VOUCHER_CATEGORY', $this->voucherCategories(Tools::getValue('categoryBox')));
|
||||
Configuration::updateValue('PS_LOYALTY_POINT_VALUE', (float)(Tools::getValue('point_value')));
|
||||
Configuration::updateValue('PS_LOYALTY_POINT_RATE', (float)(Tools::getValue('point_rate')));
|
||||
Configuration::updateValue('PS_LOYALTY_PERCENT_VALUE', (float)(Tools::getValue('point_value')));
|
||||
Configuration::updateValue('PS_LOYALTY_NONE_AWARD', (int)(Tools::getValue('PS_LOYALTY_NONE_AWARD')));
|
||||
Configuration::updateValue('PS_LOYALTY_MINIMAL', (float)(Tools::getValue('minimal')));
|
||||
|
||||
@ -266,12 +280,8 @@ class Loyalty extends Module
|
||||
|
||||
<label>'.$this->l('Ratio').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" size="2" id="point_rate" name="point_rate" value="'.(float)(Configuration::get('PS_LOYALTY_POINT_RATE')).'" /> '.$currency->sign.'
|
||||
<label for="point_rate" class="t"> = '.$this->l('1 reward point').'.</label>
|
||||
<br />
|
||||
<label for="point_value" class="t">'.$this->l('1 point = ').'</label>
|
||||
<input type="text" size="2" name="point_value" id="point_value" value="'.(float)(Configuration::get('PS_LOYALTY_POINT_VALUE')).'" /> '.$currency->sign.'
|
||||
<label for="point_value" class="t">'.$this->l('for the discount').'.</label>
|
||||
<label for="discount_value" class="t">'.$this->l('Discount by total cart').'</label>
|
||||
<input type="text" size="2" name="discount_value" id="discount_value" value="'.(float)(Configuration::get('PS_LOYALTY_PERCENT_VALUE')).'" /> %
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
<label>'.$this->l('Voucher details').'</label>
|
||||
@ -289,7 +299,7 @@ class Loyalty extends Module
|
||||
<input type="text" size="2" name="minimal" value="'.(float)(Configuration::get('PS_LOYALTY_MINIMAL')).'" /> '.$currency->sign.'
|
||||
</div>
|
||||
<div class="clear" style="margin-top: 20px"></div>
|
||||
<label>'.$this->l('Give points on discounted products').' </label>
|
||||
<label>'.$this->l('Give discount on discounted products').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="radio" name="PS_LOYALTY_NONE_AWARD" id="PS_LOYALTY_NONE_AWARD_on" value="1" '.(Configuration::get('PS_LOYALTY_NONE_AWARD') ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="PS_LOYALTY_NONE_AWARD_on"><img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Yes').'" /></label>
|
||||
@ -297,7 +307,7 @@ class Loyalty extends Module
|
||||
<label class="t" for="PS_LOYALTY_NONE_AWARD_off"><img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('No').'" /></label>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
<label>'.$this->l('Points are awarded when the order is').'</label>
|
||||
<label>'.$this->l('Discount are awarded when the order is').'</label>
|
||||
<div class="margin-form" style="margin-top:10px">
|
||||
<select id="id_order_state_validation" name="id_order_state_validation">';
|
||||
foreach ($order_states AS $order_state)
|
||||
@ -310,7 +320,7 @@ class Loyalty extends Module
|
||||
$html .= '</select>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
<label>'.$this->l('Points are cancelled when the order is').'</label>
|
||||
<label>'.$this->l('Discount are cancelled when the order is').'</label>
|
||||
<div class="margin-form" style="margin-top:10px">
|
||||
<select id="id_order_state_cancel" name="id_order_state_cancel">';
|
||||
foreach ($order_states AS $order_state)
|
||||
@ -339,7 +349,7 @@ class Loyalty extends Module
|
||||
$html .= '
|
||||
<p style="padding-left:200px;">'.$this->l('Mark the box(es) of categories in which loyalty vouchers are usable.').'</p>
|
||||
<div class="clear"></div>
|
||||
<h3 style="margin-top:20px">'.$this->l('Loyalty points progression').'</h3>
|
||||
<h3 style="margin-top:20px">'.$this->l('Loyalty discounts progression').'</h3>
|
||||
<label>'.$this->l('Initial').'</label>
|
||||
<div class="margin-form">';
|
||||
foreach ($languages as $language)
|
||||
@ -449,30 +459,29 @@ class Loyalty extends Module
|
||||
{
|
||||
if (Validate::isLoadedObject($params['cart']))
|
||||
{
|
||||
$pointsBefore = (int)(LoyaltyModule::getCartNbPoints($params['cart']));
|
||||
$pointsAfter = (int)(LoyaltyModule::getCartNbPoints($params['cart'], $product));
|
||||
$points = (int)($pointsAfter - $pointsBefore);
|
||||
$discountValueBefore = (int)(LoyaltyModule::getCartDiscountValue($params['cart']));
|
||||
$discountValueAfter = (int)(LoyaltyModule::getCartDiscountValue($params['cart'], $product));
|
||||
$discountValue = (int)($discountValueAfter - $discountValueBefore);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(int)(Configuration::get('PS_LOYALTY_NONE_AWARD')) AND Product::isDiscounted((int)$product->id))
|
||||
{
|
||||
$points = 0;
|
||||
$discountValue = 0;
|
||||
$smarty->assign('no_pts_discounted', 1);
|
||||
} else {
|
||||
$discountValue = (int)(LoyaltyModule::getDiscountValueByPrice($product->getPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? false : true, (int)($product->getIdProductAttributeMostExpensive()))));
|
||||
}
|
||||
else
|
||||
$points = (int)(LoyaltyModule::getNbPointsByPrice($product->getPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? false : true, (int)($product->getIdProductAttributeMostExpensive()))));
|
||||
$pointsAfter = $points;
|
||||
$pointsBefore = 0;
|
||||
$discountValueAfter = $discountValue;
|
||||
$discountValueBefore = 0;
|
||||
}
|
||||
|
||||
$smarty->assign(array(
|
||||
'points' => (int)($points),
|
||||
'total_points' => (int)($pointsAfter),
|
||||
'point_rate' => Configuration::get('PS_LOYALTY_POINT_RATE'),
|
||||
'point_value' => Configuration::get('PS_LOYALTY_POINT_VALUE'),
|
||||
'points_in_cart' => (int)$pointsBefore,
|
||||
'voucher' => LoyaltyModule::getVoucherValue((int)$pointsAfter)));
|
||||
'discountValue' => $discountValue,
|
||||
'total_discounts' => $discountValueAfter,
|
||||
'discount_percent' => Configuration::get('PS_LOYALTY_PERCENT_VALUE'),
|
||||
'discounts_in_cart' => $discountValueBefore
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'product.tpl');
|
||||
}
|
||||
@ -510,7 +519,7 @@ class Loyalty extends Module
|
||||
}
|
||||
|
||||
$loyaltyNew = new LoyaltyModule();
|
||||
$loyaltyNew->points = (int)(-1 * LoyaltyModule::getNbPointsByPrice($totalPrice));
|
||||
$loyaltyNew->discount_value = 0;
|
||||
$loyaltyNew->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
|
||||
$loyaltyNew->id_order = (int)$params['orderReturn']->id_order;
|
||||
$loyaltyNew->id_customer = (int)$params['orderReturn']->id_customer;
|
||||
@ -526,14 +535,14 @@ class Loyalty extends Module
|
||||
|
||||
if (Validate::isLoadedObject($params['cart']))
|
||||
{
|
||||
$points = LoyaltyModule::getCartNbPoints($params['cart']);
|
||||
$discount_value = LoyaltyModule::getCartNbPoints($params['cart']);
|
||||
$smarty->assign(array(
|
||||
'points' => (int)$points,
|
||||
'voucher' => LoyaltyModule::getVoucherValue((int)$points),
|
||||
'discount_value' => (int)$discount_value,
|
||||
'voucher' => LoyaltyModule::getVoucherValue((int)$discount_value),
|
||||
'guest_checkout' => (int)Configuration::get('PS_GUEST_CHECKOUT_ENABLED')
|
||||
));
|
||||
} else {
|
||||
$smarty->assign(array('points' => 0));
|
||||
$smarty->assign(array('discount_value' => 0));
|
||||
}
|
||||
|
||||
return $this->display(__FILE__, 'shopping-cart.tpl');
|
||||
@ -550,8 +559,8 @@ class Loyalty extends Module
|
||||
$loyalty = new LoyaltyModule();
|
||||
$loyalty->id_customer = (int)$params['customer']->id;
|
||||
$loyalty->id_order = (int)$params['order']->id;
|
||||
$loyalty->points = LoyaltyModule::getOrderNbPoints($params['order']);
|
||||
if (!Configuration::get('PS_LOYALTY_NONE_AWARD') AND (int)$loyalty->points == 0)
|
||||
$loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($params['order']);
|
||||
if (!Configuration::get('PS_LOYALTY_NONE_AWARD') AND (int)$loyalty->discount_value == 0)
|
||||
$loyalty->id_loyalty_state = LoyaltyStateModule::getNoneAwardId();
|
||||
else
|
||||
$loyalty->id_loyalty_state = LoyaltyStateModule::getDefaultId();
|
||||
@ -582,13 +591,14 @@ class Loyalty extends Module
|
||||
if ($newOrder->id == $this->loyaltyStateValidation->id_order_state)
|
||||
{
|
||||
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
|
||||
if ((int)($loyalty->points) < 0)
|
||||
$loyalty->points = abs((int)($loyalty->points));
|
||||
if ((int)($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->points = 0;
|
||||
$loyalty->discount_value = 0;
|
||||
}
|
||||
return $loyalty->save();
|
||||
}
|
||||
@ -606,13 +616,14 @@ class Loyalty extends Module
|
||||
die(Tools::displayError('Incorrect object Customer.'));
|
||||
|
||||
$details = LoyaltyModule::getAllByIdCustomer((int)$params['id_customer'], (int)$params['cookie']->id_lang);
|
||||
$points = (int)LoyaltyModule::getPointsByCustomer((int)$params['id_customer']);
|
||||
$discount_value = (int)LoyaltyModule::getVoucherValueByPercentOfOrder($details);
|
||||
|
||||
$html = '
|
||||
<br /><h2>'.$this->l('Loyalty points').' ('.(int)$points.' '.$this->l('points').')</h2>';
|
||||
<br /><h2>'.$this->l('Loyalty progam').' ('.Tools::displayPrice($discount_value, (int)Configuration::get('PS_CURRENCY_DEFAULT')).')</h2>';
|
||||
|
||||
if (!$points)
|
||||
if ($discount_value == 0) {
|
||||
return $html.' '.$this->l('This customer has no points');
|
||||
}
|
||||
|
||||
$html .= '
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
@ -620,8 +631,8 @@ class Loyalty extends Module
|
||||
<th>'.$this->l('Order').'</th>
|
||||
<th>'.$this->l('Date').'</th>
|
||||
<th>'.$this->l('Total (without shipping)').'</th>
|
||||
<th>'.$this->l('Points').'</th>
|
||||
<th>'.$this->l('Points Status').'</th>
|
||||
<th>'.$this->l('Discount').'</th>
|
||||
<th>'.$this->l('Discount Status').'</th>
|
||||
</tr>';
|
||||
foreach ($details AS $key => $loyalty)
|
||||
{
|
||||
@ -630,16 +641,16 @@ class Loyalty extends Module
|
||||
<td>'.((int)$loyalty['id'] > 0 ? '<a style="color: #268CCD; font-weight: bold; text-decoration: underline;" href="index.php?tab=AdminOrders&id_order='.$loyalty['id'].'&vieworder&token='.Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)($params['cookie']->id_employee)).'">'.$this->l('#').sprintf('%06d', $loyalty['id']).'</a>' : '--').'</td>
|
||||
<td>'.Tools::displayDate($loyalty['date'], (int)($params['cookie']->id_lang)).'</td>
|
||||
<td>'.((int)$loyalty['id'] > 0 ? $loyalty['total_without_shipping'] : '--').'</td>
|
||||
<td>'.(int)$loyalty['points'].'</td>
|
||||
<td>'.(int)$loyalty['discount_value'].'</td>
|
||||
<td>'.$loyalty['state'].'</td>
|
||||
</tr>';
|
||||
}
|
||||
$html.= '
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td colspan="2" class="bold" style="text-align: right;">'.$this->l('Total points available:').'</td>
|
||||
<td>'.$points.'</td>
|
||||
<td>'.$this->l('Voucher value:').' '.Tools::displayPrice(LoyaltyModule::getVoucherValue((int)$points, (int)Configuration::get('PS_CURRENCY_DEFAULT')), new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'))).'</td>
|
||||
<td colspan="2" class="bold" style="text-align: right;">'.$this->l('Total discounts available:').'</td>
|
||||
<td> </td>
|
||||
<td>'.$this->l('Voucher value:').' '.Tools::displayPrice(LoyaltyModule::getVoucherValueByPercentOfOrder($details, (int)Configuration::get('PS_CURRENCY_DEFAULT')), new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'))).'</td>
|
||||
</tr>
|
||||
</table>';
|
||||
|
||||
@ -651,13 +662,24 @@ class Loyalty extends Module
|
||||
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))))))
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
$loyaltyNew = new LoyaltyModule();
|
||||
$loyaltyNew->points = -1 * LoyaltyModule::getNbPointsByPrice(number_format($orderDetail->product_price * (1 + $orderDetail->tax_rate / 100), 2, '.', '')) * $orderDetail->product_quantity;
|
||||
$loyaltyNew->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
|
||||
|
||||
$price = ($params['order']->total_paid - $params['order']->total_shipping) - (number_format($orderDetail->product_price * (1 + $orderDetail->tax_rate / 100), 2, '.', '') * $orderDetail->product_quantity);
|
||||
if ($price>0) {
|
||||
$loyaltyNew->discount_value = LoyaltyModule::getDiscountValueByPrice($price);
|
||||
$loyaltyNew->id_loyalty_state = (int)LoyaltyStateModule::getDefaultId();
|
||||
} else {
|
||||
$loyaltyNew->discount_value = 0;
|
||||
$loyaltyNew->id_loyalty_state = (int)LoyaltyStateModule::getCancelId();
|
||||
}
|
||||
|
||||
$loyaltyNew->id_order = (int)$params['order']->id;
|
||||
$loyaltyNew->id_customer = (int)$loyalty->id_customer;
|
||||
$loyaltyNew->add();
|
||||
|
@ -26,17 +26,15 @@
|
||||
|
||||
<p id="loyalty" class="align_justify">
|
||||
<img src="{$module_template_dir}loyalty.gif" alt="{l s='Loyalty program' mod='loyalty'}" class="icon" />
|
||||
{if $points}
|
||||
{l s='By buying this product you can collect up to' mod='loyalty'} <b><span id="loyalty_points">{$points}</span>
|
||||
{if $points > 1}{l s='loyalty points' mod='loyalty'}{else}{l s='loyalty point' mod='loyalty'}{/if}</b>.
|
||||
{l s='Your cart will total' mod='loyalty'} <b><span id="total_loyalty_points">{$total_points}</span>
|
||||
{if $total_points > 1}{l s='points' mod='loyalty'}{else}{l s='point' mod='loyalty'}{/if}</b> {l s='that can be converted into a voucher of' mod='loyalty'}
|
||||
<span id="loyalty_price">{convertPrice price=$voucher}</span>.
|
||||
{if $discountValue}
|
||||
{l s='By buying this product you can collect up to' mod='loyalty'} <b><span id="loyalty_points">{convertPrice price=$discountValue}</span></b>.
|
||||
{l s='Your cart will total' mod='loyalty'} <b><span id="total_loyalty_points">{convertPrice price=$discountValueAfter}</span></b> {l s='that can be converted into a voucher of' mod='loyalty'}
|
||||
<span id="loyalty_price">{convertPrice price=$discountValueAfter}</span>.
|
||||
{else}
|
||||
{if isset($no_pts_discounted) && $no_pts_discounted == 1}
|
||||
{l s='No reward points for this product because there\'s already a discount.' mod='loyalty'}
|
||||
{l s='No reward discounts for this product because there\'s already a discount.' mod='loyalty'}
|
||||
{else}
|
||||
{l s='No reward points for this product.' mod='loyalty'}
|
||||
{l s='No reward discounts for this product.' mod='loyalty'}
|
||||
{/if}
|
||||
{/if}
|
||||
</p>
|
||||
|
@ -27,13 +27,12 @@
|
||||
<!-- MODULE Loyalty -->
|
||||
<p id="loyalty">
|
||||
<img src="{$module_template_dir}loyalty.gif" alt="{l s='loyalty' mod='loyalty'}" class="icon" />
|
||||
{if $points > 0}
|
||||
{l s='By checking out of this shopping cart you can collect up to' mod='loyalty'} <b>{$points}
|
||||
{if $points > 1}{l s='loyalty points' mod='loyalty'}{else}{l s='loyalty point' mod='loyalty'}{/if}</b>
|
||||
{if $discount_value > 0}
|
||||
{l s='By checking out of this shopping cart you can collect up to' mod='loyalty'} <b>{convertPrice price=$voucher}</b>
|
||||
{l s='that can be converted into a voucher of' mod='loyalty'} {convertPrice price=$voucher}{if isset($guest_checkout) && $guest_checkout}<sup>*</sup>{/if}.<br />
|
||||
{if isset($guest_checkout) && $guest_checkout}<sup>*</sup> {l s='Not available for Instant checkout order' mod='loyalty'}{/if}
|
||||
{else}
|
||||
{l s='Add some products to your shopping cart to collect some loyalty points.' mod='loyalty'}
|
||||
{l s='Add some products to your shopping cart to collect some loyalty discounts.' mod='loyalty'}
|
||||
{/if}
|
||||
</p>
|
||||
<!-- END : MODULE Loyalty -->
|
@ -43,6 +43,7 @@
|
||||
<ul class="submenu_top">
|
||||
<li><a href="{$link->getPageLink('history.php', true)}" title="{l s='Orders' mod='blockuserinfo'}">{l s='History and details of my orders' mod='blockuserinfo'}</a></li>
|
||||
<li><a href="{$link->getPageLink('identity.php', true)}" title="{l s='Information' mod='blockuserinfo'}">{l s='My personal information' mod='blockuserinfo'}</a></li>
|
||||
<li><a href="{$base_dir_ssl}modules/loyalty/loyalty-program.php" title="{l s='Loyalty program' mod='blockuserinfo'}">{l s='Loyalty program' mod='blockuserinfo'}</a></li>
|
||||
<li><a href="{$link->getPageLink('order-slip.php', true)}" title="{l s='Credit slips' mod='blockuserinfo'}">{l s='My credit slips' mod='blockuserinfo'}</a></li>
|
||||
<li><a title="Referral program" href="{$base_dir_ssl}modules/invite/invite-program.php">{l s='Programme de parrainage' mod='blockuserinfo'}</a></li>
|
||||
<li class="logout">
|
||||
|
@ -11,23 +11,29 @@
|
||||
<tr>
|
||||
<th class="first_item">{l s='Order' mod='loyalty'}</th>
|
||||
<th class="item">{l s='Date' mod='loyalty'}</th>
|
||||
<th class="item">{l s='Points' mod='loyalty'}</th>
|
||||
<th class="item">{l s='Total' mod='loyalty'}</th>
|
||||
<th class="item">{l s='Discount' mod='loyalty'}</th>
|
||||
<th class="last_item">{l s='Points Status' mod='loyalty'}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr class="alternate_item">
|
||||
<td colspan="2" class="history_method bold" style="text-align:center;">{l s='Total points available:' mod='loyalty'}</td>
|
||||
<td class="history_method" style="text-align:left;">{$totalPoints|intval}</td>
|
||||
<td class="history_method"> </td>
|
||||
<td colspan="2" class="history_method bold" style="text-align:center;">{l s='Total discount available:' mod='loyalty'}</td>
|
||||
<td class="history_method" style="text-align:left;">{Tools::displayPrice($voucher)}</td>
|
||||
<td class="history_method"> </td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
{foreach from=$displayorders item='order'}
|
||||
{if $order.id_loyalty_state == 3}
|
||||
{continue}
|
||||
{/if}
|
||||
<tr class="alternate_item">
|
||||
<td class="history_link bold">{l s='#' mod='loyalty'}{$order.id|string_format:"%06d"}</td>
|
||||
<td class="history_date">{dateFormat date=$order.date full=1}</td>
|
||||
<td class="history_method">{$order.points|intval}</td>
|
||||
<td class="history_method">{Tools::displayPrice($order.total_without_shipping)}</td>
|
||||
<td class="history_method">{Tools::displayPrice($order.reduc_value)}</td>
|
||||
<td class="history_method">{$order.state|escape:'htmlall':'UTF-8'}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
@ -96,12 +102,12 @@
|
||||
|
||||
{if $transformation_allowed}
|
||||
<p style="text-align:center; margin-top:20px">
|
||||
<a href="{$base_dir}modules/loyalty/loyalty-program.php?transform-points=true" onclick="return confirm('{l s='Are you sure you want to transform your points into vouchers?' mod='loyalty' js=1}');">{l s='Transform my points into a voucher of' mod='loyalty'} <span class="price">{convertPrice price=$voucher}</span>.</a>
|
||||
<a href="{$base_dir}modules/loyalty/loyalty-program.php?transform-points=true" onclick="return confirm('{l s='Are you sure you want to transform your discounts into vouchers?' mod='loyalty' js=1}');">{l s='Transform my discounts into a voucher of' mod='loyalty'} <span class="price">{convertPrice price=$voucher}</span>.</a>
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<br />
|
||||
<h2>{l s='My vouchers from loyalty points' mod='loyalty'}</h2>
|
||||
<h1 class="loyalty_title">{l s='My vouchers from loyalty points' mod='loyalty'}</h1>
|
||||
|
||||
{if $nbDiscounts}
|
||||
<div class="block-center" id="block-history">
|
||||
@ -132,7 +138,7 @@
|
||||
<td class="history_date">{dateFormat date=$discount->date_from}</td>
|
||||
<td class="history_date">{dateFormat date=$discount->date_to}</td>
|
||||
<td class="history_method bold">{if $discount->quantity > 0}{l s='To use' mod='loyalty'}{else}{l s='Used' mod='loyalty'}{/if}</td>
|
||||
<td class="history_method"><a href="{$smarty.server.SCRIPT_NAME}" onclick="return false" class="tips" title="{l s='Generated by these following orders' mod='loyalty'}|{foreach from=$discount->orders item=myorder name=myLoop}{l s='Order #' mod='loyalty'}{$myorder.id_order} ({displayPrice price=$myorder.total_paid currency=$myorder.id_currency}) : {if $myorder.points > 0}{$myorder.points} {l s='points.' mod='loyalty'}{else}{l s='Cancelled' mod='loyalty'}{/if}{if !$smarty.foreach.myLoop.last}|{/if}{/foreach}">{l s='more...' mod='loyalty'}</a></td>
|
||||
<td class="history_method"><a href="{$smarty.server.SCRIPT_NAME}" onclick="return false" class="tips" title="{l s='Generated by these following orders' mod='loyalty'}|{foreach from=$discount->orders item=myorder name=myLoop}{l s='Order #' mod='loyalty'}{$myorder.id_order} ({displayPrice price=$myorder.total_paid currency=$myorder.id_currency}) : {if $myorder.total_reduct > 0}{$myorder.total_reduct} {else}{l s='Cancelled' mod='loyalty'}{/if}{if !$smarty.foreach.myLoop.last}|{/if}{/foreach}">{l s='more...' mod='loyalty'}</a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
@ -162,6 +168,7 @@ $(document).ready(function()
|
||||
<p class="warning">{l s='No vouchers yet.' mod='loyalty'}</p>
|
||||
{/if}
|
||||
{else}
|
||||
<p class="warning">{l s='No reward points yet.' mod='loyalty'}</p>
|
||||
<p class="error">{l s='No reward discounts yet.' mod='loyalty'}</p>
|
||||
<p class="footer_links"><a href="{$base_dir_ssl}" title="{l s='Home' mod='loyalty'}" class="button">{l s='Home' mod='loyalty'}</a></p>
|
||||
{/if}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user