From 38143e1245898e7aad56500b2bc4608d4754a84d Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 9 Oct 2013 10:05:12 +0200 Subject: [PATCH 1/6] // Fixed stats bug (bad id for ajax request) --- controllers/admin/AdminStatsController.php | 2 +- controllers/admin/AdminTranslationsController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index f4ecc62c2..91abfe1a2 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -504,7 +504,7 @@ class AdminStatsControllerCore extends AdminStatsTabController else { $country = new Country($row['id_country'], $this->context->language->id); - $value = sprintf($this->l('%.1f%% %s'), $row['orders'], $country->name); + $value = sprintf($this->l('%d%% %s'), $row['orders'], $country->name); } ConfigurationKPI::updateValue('MAIN_COUNTRY', array($this->context->language->id => $value)); diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index c0257f4e7..d705f9da2 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -1272,7 +1272,7 @@ class AdminTranslationsControllerCore extends AdminController $kpis[] = $helper->generate(); $helper = new HelperKpi(); - $helper->id = 'box-country'; + $helper->id = 'box-translations'; $helper->icon = 'icon-list'; $helper->color = 'color3'; $helper->title = $this->l('Front Office Translations'); From e16676efaa302767bc62a7d81703c61d8e8100f1 Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Wed, 9 Oct 2013 10:51:04 +0200 Subject: [PATCH 2/6] //added prefix & suffix on helper form --- .../default/template/helpers/form/form.tpl | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/admin-dev/themes/default/template/helpers/form/form.tpl b/admin-dev/themes/default/template/helpers/form/form.tpl index 2f320e36e..dae22d7a4 100644 --- a/admin-dev/themes/default/template/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/helpers/form/form.tpl @@ -102,10 +102,19 @@ {/literal} {/if} - {if isset($input.maxchar)} + {if isset($input.maxchar) || isset($input.prefix) || isset($input.suffix)}
- {$input.maxchar} {/if} + {if isset($input.maxchar)} + + {$input.maxchar} + + {/if} + {if isset($input.prefix)} + + {$input.prefix} + + {/if} - {if isset($input.maxchar)} + {if isset($input.suffix)} + + {$input.suffix} + + {/if} + {if isset($input.maxchar) || isset($input.prefix) || isset($input.suffix)}
{/if} {if $languages|count > 1} @@ -175,10 +189,17 @@ {/literal} {/if} {assign var='value_text' value=$fields_value[$input.name]} - {if isset($input.maxchar)} + {if isset($input.maxchar) || isset($input.prefix) || isset($input.suffix)}
+ {/if} + {if isset($input.maxchar)} {$input.maxchar} {/if} + {if isset($input.prefix)} + + {$input.prefix} + + {/if} - {if isset($input.suffix)}{$input.suffix}{/if} - {if isset($input.maxchar)} + {if isset($input.suffix)} + + {$input.suffix} + + {/if} + + {if isset($input.maxchar) || isset($input.prefix) || isset($input.suffix)}
{/if} {if isset($input.maxchar)} From 623b8c7960904de35484503d212a6bfdb0d1b170 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 9 Oct 2013 10:54:59 +0200 Subject: [PATCH 3/6] // Added expense management to profitability KPI --- .../default/template/helpers/kpi/kpi.tpl | 4 +- classes/helper/HelperKpi.php | 4 +- .../admin/AdminDashboardController.php | 2 +- controllers/admin/AdminOrdersController.php | 4 +- controllers/admin/AdminStatsController.php | 70 +++++++++++++------ 5 files changed, 58 insertions(+), 26 deletions(-) diff --git a/admin-dev/themes/default/template/helpers/kpi/kpi.tpl b/admin-dev/themes/default/template/helpers/kpi/kpi.tpl index 32294bc1a..f94973ab3 100644 --- a/admin-dev/themes/default/template/helpers/kpi/kpi.tpl +++ b/admin-dev/themes/default/template/helpers/kpi/kpi.tpl @@ -22,7 +22,7 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -
+<{if $href}a style="display:block" href="{$href|escape}"{else}div{/if} id="{$id|escape}" class="col-lg-3 box-stats {$color|escape}" > {if $icon}{/if} {if $chart}
@@ -32,7 +32,7 @@ {/if} {$title|escape}
{$subtitle|escape}
{$value|escape} -
+ {if $source != ''} -

'.$this->l('Loyalty Program').'

-
-
- '.$this->l('Settings').' - - -
- '.$currency->sign.' - -
- - '.$currency->sign.' - -
-
- -
'; - foreach ($languages as $language) - $this->html .= ' -
- -
'; - $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'voucher_details', true); - $this->html .= '
-
- -
- '.$currency->sign.' -
-
- -
- - - - -
-
- -
- -
-
- -
- -
-
- '; - $index = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY')); - $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : $index; - - $helper = new Helper(); - $this->html .= '
'.$helper->renderCategoryTree(null, $indexedCategories).'
'; - $this->html .= ' -

'.$this->l('Mark the box(es) of categories in which loyalty vouchers are usable.').'

-
-

'.$this->l('Loyalty points progression').'

- -
'; - foreach ($languages as $language) - $this->html .= ' -
- -
'; - $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'default_loyalty_state', true); - $this->html .= '
-
- -
'; - foreach ($languages as $language) - $this->html .= ' -
- -
'; - $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'none_award_loyalty_state', true); - $this->html .= '
-
- -
'; - foreach ($languages as $language) - $this->html .= ' -
- -
'; - $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'convert_loyalty_state', true); - $this->html .= '
-
- -
'; - foreach ($languages as $language) - $this->html .= ' -
- -
'; - $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'validation_loyalty_state', true); - $this->html .= '
-
- -
'; - foreach ($languages as $language) - $this->html .= ' -
- -
'; - $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'cancel_loyalty_state', true); - $this->html .= '
-
- -
-
-
'; + $this->html .= $this->renderForm(); return $this->html; } - 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 = count($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) { @@ -672,4 +496,191 @@ class Loyalty extends Module return (array_key_exists($key, $translations)) ? $translations[$key] : $key; } + + public function renderForm() + { + $order_states = OrderState::getOrderStates($this->context->language->id); + $currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT'))); + if (Tools::getValue('categoryBox')) + $selected_categories = Tools::getValue('categoryBox'); + else + $selected_categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY')); + + $fields_form_1 = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Settings'), + 'icon' => 'icon-cogs' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Ratio'), + 'name' => 'point_rate', + 'prefix' => $currency->sign, + 'suffix' => $this->l('= 1 reward point.'), + ), + array( + 'type' => 'text', + 'label' => $this->l('1 point ='), + 'name' => 'point_value', + 'prefix' => $currency->sign, + 'suffix' => $this->l('for the discount.'), + ), + array( + 'type' => 'text', + 'label' => $this->l('Voucher details'), + 'name' => 'voucher_details', + 'lang' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Minimum amount in which the voucher can be used'), + 'name' => 'minimal', + 'prefix' => $currency->sign, + 'class' => 'fixed-width-sm', + ), + array( + 'type' => 'select', + 'label' => $this->l('Points are awarded when the order is'), + 'name' => 'id_order_state_validation', + 'options' => array( + 'query' => $order_states, + 'id' => 'id_order_state', + 'name' => 'name', + ) + ), + array( + 'type' => 'select', + 'label' => $this->l('Points are cancelled when the order is'), + 'name' => 'id_order_state_cancel', + 'options' => array( + 'query' => $order_states, + 'id' => 'id_order_state', + 'name' => 'name', + ) + ), + array( + 'type' => 'switch', + 'label' => $this->l('Give points on discounted products'), + 'name' => 'PS_LOYALTY_NONE_AWARD', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ) + ), + array( + 'type' => 'categories', + 'label' => $this->l('Vouchers created by the loyalty system can be used in the following categories :'), + 'name' => 'categoryBox', + 'desc' => $this->l('Mark the box(es) of categories in which loyalty vouchers are usable.'), + 'tree' => array( + 'use_search' => false, + 'id' => 'categoryBox', + 'use_checkbox' => true, + 'selected_categories' => $selected_categories, + ), + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-primary') + ), + ); + + $fields_form_2 = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Loyalty points progression'), + 'icon' => 'icon-cogs' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Initial'), + 'name' => 'default_loyalty_state', + 'lang' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Unavailable'), + 'name' => 'none_award_loyalty_state', + 'lang' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Converted'), + 'name' => 'convert_loyalty_state', + 'lang' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Validation'), + 'name' => 'validation_loyalty_state', + 'lang' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Cancelled'), + 'name' => 'cancel_loyalty_state', + 'lang' => true, + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-primary') + ), + ); + + $helper = new HelperForm(); + $helper->show_toolbar = false; + $helper->table = $this->table; + $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); + $helper->default_form_language = $lang->id; + $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; + $helper->identifier = $this->identifier; + $helper->submit_action = 'submitLoyalty'; + $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; + $helper->token = Tools::getAdminTokenLite('AdminModules'); + $helper->tpl_vars = array( + 'fields_value' => $this->getConfigFieldsValues(), + 'languages' => $this->context->controller->getLanguages(), + 'id_language' => $this->context->language->id + ); + return $helper->generateForm(array($fields_form_1, $fields_form_2)); + } + + public function getConfigFieldsValues() + { + $fields_values = array( + 'point_rate' => Tools::getValue('PS_LOYALTY_POINT_RATE', Configuration::get('PS_LOYALTY_POINT_RATE')), + 'point_value' => Tools::getValue('PS_LOYALTY_POINT_VALUE', Configuration::get('PS_LOYALTY_POINT_VALUE')), + 'PS_LOYALTY_NONE_AWARD' => Tools::getValue('PS_LOYALTY_NONE_AWARD', Configuration::get('PS_LOYALTY_NONE_AWARD')), + 'minimal' => Tools::getValue('PS_LOYALTY_MINIMAL', Configuration::get('PS_LOYALTY_MINIMAL')), + 'id_order_state_validation' => Tools::getValue('id_order_state_validation', $this->loyaltyStateValidation->id_order_state), + 'id_order_state_cancel' => Tools::getValue('id_order_state_cancel', $this->loyaltyStateCancel->id_order_state), + + ); + + $languages = Language::getLanguages(false); + + foreach ($languages as $lang) + { + $fields_values['voucher_details'][$lang['id_lang']] = Tools::getValue('voucher_details_'.(int)$lang['id_lang'], Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)$lang['id_lang'])); + $fields_values['default_loyalty_state'][$lang['id_lang']] = Tools::getValue('default_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateDefault->name[(int)($lang['id_lang'])]); + $fields_values['validation_loyalty_state'][$lang['id_lang']] = Tools::getValue('validation_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateValidation->name[(int)($lang['id_lang'])]); + $fields_values['cancel_loyalty_state'][$lang['id_lang']] = Tools::getValue('cancel_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateCancel->name[(int)($lang['id_lang'])]); + $fields_values['convert_loyalty_state'][$lang['id_lang']] = Tools::getValue('convert_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateConvert->name[(int)($lang['id_lang'])]); + $fields_values['none_award_loyalty_state'][$lang['id_lang']] = Tools::getValue('none_award_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateNoneAward->name[(int)($lang['id_lang'])]); + } + return $fields_values; + } } \ No newline at end of file