From 8f08f678124664ee35774f349228e12553586be5 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Tue, 24 Sep 2013 12:22:40 +0200 Subject: [PATCH] [+] BO : Added fees configuration for the dashboard --- classes/controller/AdminController.php | 2 +- .../admin/AdminDashboardController.php | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index eac02bbf2..182d46109 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -2128,7 +2128,7 @@ class AdminControllerCore extends Controller elseif (isset($_POST['submitReset'.$this->list_id])) $this->action = 'reset_filters'; /* Submit options list */ - elseif (Tools::getValue('submitOptions'.$this->table) || Tools::getValue('submitOptions')) + elseif (Tools::isSubmit('submitOptions'.$this->table) || Tools::isSubmit('submitOptions')) { $this->display = 'options'; if ($this->tabAccess['edit'] === '1') diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php index ecd0a3978..db0b49245 100644 --- a/controllers/admin/AdminDashboardController.php +++ b/controllers/admin/AdminDashboardController.php @@ -30,7 +30,11 @@ class AdminDashboardControllerCore extends AdminController { $this->bootstrap = true; $this->display = 'view'; + parent::__construct(); + + if (Tools::isSubmit('profitability_conf') || Tools::isSubmit('submitOptions')) + $this->fields_options = $this->getOptionFields(); } public function setMedia() @@ -49,8 +53,86 @@ class AdminDashboardControllerCore extends AdminController )); } + protected function getOptionFields() + { + $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); + $fields = array(); + + $modules = Module::getModulesOnDisk(true); + foreach ($modules as $module) + if ($module->tab == 'payments_gateways' && $module->id) + { + $fields['CONF_'.strtoupper($module->name).'_FIXED_FEE'] = array( + 'title' => sprintf($this->l('Fixed fee / %s'), $module->displayName), + 'desc' => sprintf($this->l('Choose a fixed fee for each order placed with %s.'), $module->displayName), + 'validation' => 'isPrice', + 'cast' => 'floatval', + 'type' => 'text', + 'default' => '0', + 'suffix' => $currency->iso_code + ); + $fields['CONF_'.strtoupper($module->name).'_VAR_FEE'] = array( + 'title' => sprintf($this->l('Variable fee / %s'), $module->displayName), + 'desc' => sprintf($this->l('Choose a variable fee for each order placed with %s. It will be applied on the total paid with taxes.'), $module->displayName), + 'validation' => 'isPercentage', + 'cast' => 'floatval', + 'type' => 'text', + 'default' => '0', + 'suffix' => '%' + ); + } + $fields['CONF_ORDER_FIXED_FEES'] = array( + 'title' => $this->l('Other fixed fees'), + 'desc' => $this->l('Other fixed fees applied to each order.'), + 'validation' => 'isPrice', + 'cast' => 'floatval', + 'type' => 'text', + 'default' => '0', + 'suffix' => $currency->iso_code + ); + $fields['CONF_SHIPPING_MARGIN'] = array( + 'title' => $this->l('Shipping Margin'), + 'desc' => $this->l('Profit margin on your shipping fees.'), + 'validation' => 'isPercentage', + 'cast' => 'floatval', + 'type' => 'text', + 'default' => '0', + 'suffix' => '%' + ); + $fields['CONF_MONTHLY_FEES'] = array( + 'title' => $this->l('Monthly fees'), + 'desc' => $this->l('Monthly fees like hosting, adwords, etc.'), + 'validation' => 'isPrice', + 'cast' => 'floatval', + 'type' => 'text', + 'default' => '0', + 'suffix' => $currency->iso_code + ); + $fields['CONF_YEARLY_FEES'] = array( + 'title' => $this->l('Yearly fees'), + 'desc' => $this->l('Yearly fees like hosting, subscriptions, etc.'), + 'validation' => 'isPrice', + 'cast' => 'floatval', + 'type' => 'text', + 'default' => '0', + 'suffix' => $currency->iso_code + ); + + return array( + 'profitability' => array( + 'title' => $this->l('Profitability Configuration'), + 'icon' => 'tab-preferences', + 'fields' => $fields, + 'submit' => array('title' => $this->l('Save'), 'class' => 'button'), + ), + ); + } + public function renderView() { + if (Tools::isSubmit('profitability_conf')) + return parent::renderOptions(); + $translations = array( 'Calendar' => $this->l('Calendar', 'AdminStatsTab'), 'Day' => $this->l('Day', 'AdminStatsTab'),