Merge branch 'ticket-fidelite' into develop

This commit is contained in:
Marion Muszynski 2016-06-08 12:02:38 +02:00
commit 775276a367
2 changed files with 36 additions and 7 deletions

View File

@ -182,7 +182,6 @@ class LoyaltyModule extends ObjectModel
$query = ' $query = '
SELECT f.id_order AS id, f.date_add AS date, f.discount_value, f.id_loyalty, f.id_loyalty_state, fsl.name state SELECT f.id_order AS id, f.date_add AS date, f.discount_value, f.id_loyalty, f.id_loyalty_state, fsl.name state
FROM `'._DB_PREFIX_.'loyalty` f 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).') 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); WHERE f.id_customer = '.(int)($id_customer);
if ($onlyValidate === true) if ($onlyValidate === true)
@ -198,7 +197,6 @@ class LoyaltyModule extends ObjectModel
$query = ' $query = '
SELECT COUNT(f.`id_loyalty`) SELECT COUNT(f.`id_loyalty`)
FROM `'._DB_PREFIX_.'loyalty` f FROM `'._DB_PREFIX_.'loyalty` f
-- LEFT JOIN `'._DB_PREFIX_.'orders` o ON (f.id_order = o.id_order)
WHERE f.`id_customer` = '.(int)($id_customer); WHERE f.`id_customer` = '.(int)($id_customer);
if ($notCancel === true) if ($notCancel === true)
$query .= ' AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId(); $query .= ' AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId();
@ -206,10 +204,21 @@ class LoyaltyModule extends ObjectModel
return Db::getInstance()->getValue($query); return Db::getInstance()->getValue($query);
} }
public static function getOrdersWithDiscountByIdCustomer($id_customer, $notCancel = true)
{
$query = '
SELECT f.`id_loyalty`,f.`id_loyalty_state`,f.`discount_value`
FROM `'._DB_PREFIX_.'loyalty` f
WHERE f.`id_customer` = '.(int)($id_customer);
if ($notCancel === true)
$query .= ' AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId();
return Db::getInstance()->ExecuteS($query);
}
public static function getAllByIdCustomerCustom($id_customer, $id_lang, $onlyValidate = false, $pagination = false, $nb = 10, $page = 1, $onlyDefault = false) public static function getAllByIdCustomerCustom($id_customer, $id_lang, $onlyValidate = false, $pagination = false, $nb = 10, $page = 1, $onlyDefault = false)
{ {
$percent = (float)(Configuration::get('PS_LOYALTY_PERCENT_VALUE') / 100); /*$percent = (float)(Configuration::get('PS_LOYALTY_PERCENT_VALUE') / 100);
$query = ' $query = '
SELECT f.id_order AS id, f.date_add AS date, SELECT f.id_order AS id, f.date_add AS date,
(o.total_paid - o.total_shipping) total_without_shipping, (o.total_paid - o.total_shipping) total_without_shipping,
@ -218,6 +227,12 @@ class LoyaltyModule extends ObjectModel
FROM `'._DB_PREFIX_.'loyalty` f FROM `'._DB_PREFIX_.'loyalty` f
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (f.id_order = o.id_order) 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).') 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).'*/
$query = '
SELECT f.id_order AS id, f.date_add AS date, f.discount_value, f.id_loyalty, f.id_loyalty_state, fsl.name state
FROM `'._DB_PREFIX_.'loyalty` f
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).' WHERE f.id_customer = '.(int)($id_customer).'
'.(($onlyValidate)?'':' AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId()); '.(($onlyValidate)?'':' AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId());
if ($onlyValidate) { if ($onlyValidate) {

View File

@ -44,12 +44,25 @@ Tools::addJS(array(_PS_JS_DIR_.'jquery/jquery.dimensions.js',_PS_JS_DIR_.'jquery
$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)); $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), true, false, $nb = 10, $page = 1); //$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)); //$total_discount = LoyaltyModule::getVoucherValueByPercentOfOrder($orderToConvert, (int)($cookie->id_currency));
$total_discount = Db::getInstance()->getValue(' /*$total_discount = Db::getInstance()->getValue('
SELECT SUM(`discount_value`) FROM `'._DB_PREFIX_.'loyalty` SELECT SUM(`discount_value`) FROM `'._DB_PREFIX_.'loyalty`
WHERE `id_loyalty_state`=2 WHERE `id_loyalty_state`=2
AND `id_discount`=0 AND `id_discount`=0
AND `id_customer` = ' .(int) $cookie->id_customer AND `id_customer` = ' .(int) $cookie->id_customer
); );*/
$allOrders = LoyaltyModule::getOrdersWithDiscountByIdCustomer((int) $cookie->id_customer);
$total_discount = 0;
if (!empty($allOrders)) {
$nb_orders = count($allOrders);
foreach ($allOrders as $key => $order) {
if ($order['id_loyalty_state'] !=2){
continue;
}
$total_discount += (float)$order['id_loyalty_state'];
}
} else {
$nb_orders = 0;
}
/* transform point into voucher if needed */ /* transform point into voucher if needed */
if (Tools::getValue('transform-points') == 'true' AND $total_discount > 0) if (Tools::getValue('transform-points') == 'true' AND $total_discount > 0)
@ -123,7 +136,8 @@ 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( $smarty->assign(array(
'nb_orders' => (int)LoyaltyModule::getNbOrdersByIdCustomer((int)($cookie->id_customer)), /*'nb_orders' => (int)LoyaltyModule::getNbOrdersByIdCustomer((int)($cookie->id_customer)),*/
'nb_orders' => $nb_orders,
'displayorders' => $displayorders, 'displayorders' => $displayorders,
'pagination_link' => __PS_BASE_URI__.'modules/loyalty/loyalty-program.php', 'pagination_link' => __PS_BASE_URI__.'modules/loyalty/loyalty-program.php',
'voucher' => $total_discount, 'voucher' => $total_discount,