diff --git a/modules/loyalty/LoyaltyModule.php b/modules/loyalty/LoyaltyModule.php
index 46bef2a7..3a8fb302 100755
--- a/modules/loyalty/LoyaltyModule.php
+++ b/modules/loyalty/LoyaltyModule.php
@@ -133,13 +133,14 @@ class LoyaltyModule extends ObjectModel
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'];
+ if ($orders && !empty($orders)) {
+ foreach ($orders as $key => $order) {
+ $value += $order['discount_value'];
+ }
}
return (float)Tools::convertPrice($value, new Currency((int)$id_currency));
@@ -192,12 +193,14 @@ 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)
+ public static function getAllByIdCustomerCustom($id_customer, $id_lang, $onlyValidate = false, $pagination = false, $nb = 10, $page = 1, $onlyDefault = false)
{
+ $percent = (float)(1.75 / 100);
+
$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,
+ (('.(float)$percent.' * (o.total_paid - o.total_shipping))) 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)
@@ -206,6 +209,8 @@ class LoyaltyModule extends ObjectModel
AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId();
if ($onlyValidate) {
$query .= ' AND f.id_loyalty_state = '.(int)LoyaltyStateModule::getValidationId();
+ } elseif ($onlyDefault){
+ $query .= ' AND f.id_loyalty_state = '.(int)LoyaltyStateModule::getDefaultId();
}
$query .= ' GROUP BY f.id_loyalty '.
($pagination ? 'LIMIT '.(((int)($page) - 1) * (int)($nb)).', '.(int)($nb) : '');
@@ -238,11 +243,12 @@ class LoyaltyModule extends ObjectModel
{
$f = new LoyaltyModule((int)$item['id_loyalty']);
- if ($f->discount_value = 0) {
+ if ($f->discount_value == 0) {
continue;
}
$f->id_discount = (int)$discount->id;
+ $f->discount_value = $f->discount_value;
$f->id_loyalty_state = (int)LoyaltyStateModule::getConvertId();
$f->save();
}
@@ -274,10 +280,10 @@ class LoyaltyModule extends ObjectModel
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()));
-
+ 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)
@@ -287,6 +293,7 @@ class LoyaltyModule extends ObjectModel
$items[$key]['id_lang'] = (int)$order->id_lang;
$items[$key]['total_paid'] = $order->total_paid;
$items[$key]['total_shipping'] = $order->total_shipping;
+ $items[$key]['discount_value'] = $item['discount_value'];
}
return $items;
}
diff --git a/modules/loyalty/loyalty-program.php b/modules/loyalty/loyalty-program.php
index a6479ad5..b01d14e3 100755
--- a/modules/loyalty/loyalty-program.php
+++ b/modules/loyalty/loyalty-program.php
@@ -41,8 +41,9 @@ 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'));
$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);
+$orderToConvert = LoyaltyModule::getAllByIdCustomerCustom((int)($cookie->id_customer), (int)($cookie->id_lang), true, false, $nb = 10, $page = 1);
$total_discount = LoyaltyModule::getVoucherValueByPercentOfOrder($orderToConvert, (int)($cookie->id_currency));
+
/* transform point into voucher if needed */
if (Tools::getValue('transform-points') == 'true' AND $total_discount > 0)
{
@@ -112,10 +113,10 @@ if (Tools::getValue('transform-points') == 'true' AND $total_discount > 0)
include(dirname(__FILE__).'/../../header.php');
-$orders = LoyaltyModule::getAllByIdCustomer((int)($cookie->id_customer), (int)($cookie->id_lang));
+//$orders = LoyaltyModule::getAllByIdCustomer((int)($cookie->id_customer), (int)($cookie->id_lang));
$smarty->assign(array(
- 'orders' => $orders,
+ //'orders' => $orders,
'displayorders' => $displayorders,
'pagination_link' => __PS_BASE_URI__.'modules/loyalty/loyalty-program.php',
'voucher' => $total_discount,
@@ -136,7 +137,7 @@ if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int)($cookie->id_cus
foreach ($ids_discount AS $key => $discount)
{
$discounts[$key] = new Discount((int)$discount['id_discount'], (int)($cookie->id_lang));
- $discounts[$key]->orders = LoyaltyModule::getOrdersByIdDiscount((int)$discount['id_discount']);
+ $discounts[$key]->orders = LoyaltyModule::getOrdersByIdDiscountCustom((int)$discounts[$key]->id);
}
}
@@ -159,12 +160,13 @@ else
$categoriesNames = Tools::truncate(implode(', ', $categoriesNames), 100).'.';
else
$categoriesNames = null;
-}
+}
$smarty->assign(array(
'nbDiscounts' => (int)$nbDiscounts,
'discounts' => $discounts,
'minimalLoyalty' => (float)Configuration::get('PS_LOYALTY_MINIMAL'),
- 'categories' => $categoriesNames));
+ 'categories' => $categoriesNames
+));
echo Module::display(dirname(__FILE__).'/loyalty.php', 'loyalty.tpl');
diff --git a/modules/loyalty/loyalty.php b/modules/loyalty/loyalty.php
index 3fad5285..9d8d6ba0 100755
--- a/modules/loyalty/loyalty.php
+++ b/modules/loyalty/loyalty.php
@@ -616,7 +616,8 @@ class Loyalty extends Module
die(Tools::displayError('Incorrect object Customer.'));
$details = LoyaltyModule::getAllByIdCustomer((int)$params['id_customer'], (int)$params['cookie']->id_lang);
- $discount_value = LoyaltyModule::getVoucherValueByPercentOfOrder($details);
+ $valid_orders = LoyaltyModule::getAllByIdCustomerCustom((int)$params['id_customer'], (int)$params['cookie']->id_lang, false, false, $nb = 10, $page = 1, true);
+ $discount_value = LoyaltyModule::getVoucherValueByPercentOfOrder($valid_orders, (int)Configuration::get('PS_CURRENCY_DEFAULT'));
$html = '
- | {l s='Total discount available:' mod='loyalty'} | -{Tools::displayPrice($voucher)} | +{l s='Total discount available:' mod='loyalty'} | +{Tools::displayPrice($voucher)} |