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 = '

'.$this->l('Loyalty progam').' ('.Tools::displayPrice($discount_value, (int)Configuration::get('PS_CURRENCY_DEFAULT')).')

'; @@ -640,17 +641,18 @@ class Loyalty extends Module '.((int)$loyalty['id'] > 0 ? ''.$this->l('#').sprintf('%06d', $loyalty['id']).'' : '--').' '.Tools::displayDate($loyalty['date'], (int)($params['cookie']->id_lang)).' - '.((int)$loyalty['id'] > 0 ? $loyalty['total_without_shipping'] : '--').' - '.(int)$loyalty['discount_value'].' + '.((int)$loyalty['id'] > 0 ? Tools::displayPrice($loyalty['total_without_shipping'],(int)Configuration::get('PS_CURRENCY_DEFAULT')) : '--').' + '.Tools::displayPrice((float)$loyalty['discount_value'],(int)Configuration::get('PS_CURRENCY_DEFAULT')).' '.$loyalty['state'].' '; } $html.= '   - '.$this->l('Total discounts available:').'   - '.$this->l('Voucher value:').' '.Tools::displayPrice(LoyaltyModule::getVoucherValueByPercentOfOrder($details, (int)Configuration::get('PS_CURRENCY_DEFAULT')), new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'))).' + '.$this->l('Voucher value:').' + '.Tools::displayPrice(LoyaltyModule::getVoucherValueByPercentOfOrder($details, (int)Configuration::get('PS_CURRENCY_DEFAULT')), new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'))).' +   '; diff --git a/override/classes/Discount.php b/override/classes/Discount.php index 9f3e4937..22f69640 100644 --- a/override/classes/Discount.php +++ b/override/classes/Discount.php @@ -1,7 +1,8 @@ .gv_param input { float: left; } +/** Module loyalty **/ + +a.loyalty-transform, .history_method span.total-discount-loyalty{ + text-align: center; + text-transform: none; + border: 0px; + color: #FFF; + font-size: 12px; + padding: 8px 20px 8px 20px; + text-decoration: none; + font-weight: normal; + /* background: #504d8b url("../img/arrow.png") right 9px no-repeat; */ + background: #504d8b; + -moz-border-radius: 20px; + -webkit-border-radius: 20px; + border-radius: 20px; + font-family: georgia, times new roman, serif; + font-style: italic; + font-size: 13px; +} + @keyframes slideInDown { 0% { -webkit-transform: translateY(-500px); diff --git a/themes/site/modules/blockuserinfo/blockuserinfo.tpl b/themes/site/modules/blockuserinfo/blockuserinfo.tpl index 8b333eaa..1079b734 100755 --- a/themes/site/modules/blockuserinfo/blockuserinfo.tpl +++ b/themes/site/modules/blockuserinfo/blockuserinfo.tpl @@ -49,7 +49,7 @@
  • {l s='Log out' mod='blockuserinfo'}
  • - + diff --git a/themes/site/modules/loyalty/loyalty.tpl b/themes/site/modules/loyalty/loyalty.tpl index 02f6d346..ce1dbfd9 100755 --- a/themes/site/modules/loyalty/loyalty.tpl +++ b/themes/site/modules/loyalty/loyalty.tpl @@ -3,9 +3,9 @@

    {l s='My loyalty points' mod='loyalty'}

    -{if $orders} +{if $displayorders}
    - {if $orders && count($orders)} + {if $displayorders && count($displayorders)} @@ -19,8 +19,8 @@ - - + + @@ -45,7 +45,7 @@ {/if} - + {/foreach} @@ -169,6 +169,12 @@ $(document).ready(function() {/if} {else}

    {l s='No reward discounts yet.' mod='loyalty'}

    - {/if} +
    + + \ No newline at end of file diff --git a/themes/site_mobile/css/style.css b/themes/site_mobile/css/style.css index aae6a59c..622d504e 100755 --- a/themes/site_mobile/css/style.css +++ b/themes/site_mobile/css/style.css @@ -4465,5 +4465,15 @@ body#index .jqibuttons span.gradient{ background: #504d8b; } - #cookiescontent { padding: 10px; font-size: 12px; } + +/** Module loyalty **/ +.exclusive.loyalty-transform { + background: #504c89; + color: #fff; + font-size: 12px; + font-weight: bold; + height: 20px; + line-height: 25px; + padding: 10px; +} diff --git a/themes/site_mobile/modules/loyalty/loyalty.tpl b/themes/site_mobile/modules/loyalty/loyalty.tpl index f1a8fa5a..dfb70d7f 100755 --- a/themes/site_mobile/modules/loyalty/loyalty.tpl +++ b/themes/site_mobile/modules/loyalty/loyalty.tpl @@ -29,31 +29,34 @@

    {l s='My loyalty points' mod='loyalty'}

    -{if $orders} -
    - {if $orders && count($orders)} +{if $displayorders} +
    + {if $displayorders && count($displayorders)}
     {l s='Total discount available:' mod='loyalty'}{Tools::displayPrice($voucher)}{l s='Total discount available:' mod='loyalty'}{Tools::displayPrice($voucher)}  
    {dateFormat date=$discount->date_from} {dateFormat date=$discount->date_to} {if $discount->quantity > 0}{l s='To use' mod='loyalty'}{else}{l s='Used' mod='loyalty'}{/if}{l s='more...' mod='loyalty'}{l s='more...' mod='loyalty'}
    - + - - + + {foreach from=$displayorders item='order'} + {if $order.id_loyalty_state == 3} + {continue} + {/if} - - + + {/foreach} @@ -65,7 +68,7 @@ {/if} - + {/foreach} @@ -194,10 +197,9 @@ $(document).ready(function()

    {l s='No reward points yet.' mod='loyalty'}

    {/if} -
    -

    - {if $points} + {if $discountValue} Loyalty program - {l s='Loyalty points' mod='loyalty'} {convertPrice price=$voucher} + {l s='Loyalty points' mod='loyalty'} {convertPrice price=$discountValue} {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 discount 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 discount for this product.' mod='loyalty'} {/if} {/if}

    diff --git a/themes/site_mobile/modules/loyalty/shopping-cart.tpl b/themes/site_mobile/modules/loyalty/shopping-cart.tpl index ea24880c..2abdd75c 100755 --- a/themes/site_mobile/modules/loyalty/shopping-cart.tpl +++ b/themes/site_mobile/modules/loyalty/shopping-cart.tpl @@ -26,7 +26,7 @@

    - {if $points > 0} + {if $discount_value > 0} {l s='By checking out of this shopping cart you can collect up to' mod='loyalty'} {convertPrice price=$voucher} {l s='to use during your next orders' mod='loyalty'} {else} {l s='Add some products to your shopping cart to collect some loyalty points.' mod='loyalty'}

    {l s='Order' mod='loyalty'} {l s='Date' mod='loyalty'}{l s='Points' mod='loyalty'}{l s='Discount' mod='loyalty'} {l s='Points Status' mod='loyalty'}
    {l s='Total points available:' mod='loyalty'}{$totalPoints|intval}{l s='Total discount available:' mod='loyalty'}{Tools::displayPrice($voucher)}  
    {dateFormat date=$order.date full=1}{$order.points|intval}{dateFormat date=$order.date}{Tools::displayPrice($order.reduc_value)} {$order.state|escape:'htmlall':'UTF-8'}
    {if $discount->quantity > 0}{l s='To use' mod='loyalty'}{else}{l s='Used' mod='loyalty'}{/if}{l s='more...' mod='loyalty'}{l s='more...' mod='loyalty'}