From ec3b7738e8a55641838c09e654c9ee2d3364b5e0 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Thu, 27 Oct 2011 14:36:29 +0000 Subject: [PATCH] [*] BO : #PSFV-94 - added AdminRangeWeightController --- admin-dev/tabs/AdminRangeWeight.php | 118 ----------------- .../themes/template/helper/form/form.tpl | 1 + .../admin/AdminRangeWeightController.php | 124 ++++++++++++++++++ 3 files changed, 125 insertions(+), 118 deletions(-) delete mode 100644 admin-dev/tabs/AdminRangeWeight.php create mode 100644 controllers/admin/AdminRangeWeightController.php diff --git a/admin-dev/tabs/AdminRangeWeight.php b/admin-dev/tabs/AdminRangeWeight.php deleted file mode 100644 index 8389cf58f..000000000 --- a/admin-dev/tabs/AdminRangeWeight.php +++ /dev/null @@ -1,118 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 6844 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -class AdminRangeWeight extends AdminTab -{ - public function __construct() - { - $this->table = 'range_weight'; - $this->className = 'RangeWeight'; - $this->lang = false; - $this->edit = true; - $this->delete = true; - - $this->fieldsDisplay = array( - 'id_range_weight' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), - 'carrier_name' => array('title' => $this->l('Carrier'), 'align' => 'center', 'width' => 25, 'filter_key' => 'ca!name'), - 'delimiter1' => array('title' => $this->l('From'), 'width' => 86, 'float' => true, 'suffix' => Configuration::get('PS_WEIGHT_UNIT'), 'align' => 'right'), - 'delimiter2' => array('title' => $this->l('To'), 'width' => 86, 'float' => true,'suffix' => Configuration::get('PS_WEIGHT_UNIT'), 'align' => 'right')); - - $this->_join = 'LEFT JOIN '._DB_PREFIX_.'carrier ca ON (ca.`id_carrier` = a.`id_carrier`)'; - $this->_select = 'ca.`name` AS carrier_name'; - $this->_where = 'AND ca.`deleted` = 0'; - - parent::__construct(); - } - - public function displayListContent($token = NULL) - { - foreach ($this->_list as $key => $list) - if ($list['carrier_name'] == '0') - $this->_list[$key]['carrier_name'] = Configuration::get('PS_SHOP_NAME'); - parent::displayListContent($token); - } - - public function postProcess() - { - if (isset($_POST['submitAdd'.$this->table]) AND Tools::getValue('delimiter1') >= Tools::getValue('delimiter2')) - $this->_errors[] = Tools::displayError('Invalid range'); - else - parent::postProcess(); - } - - public function displayForm($isMainTab = true) - { - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - - $carrierArray = array(); - $carriers = Carrier::getCarriers((int)(Configuration::get('PS_LANG_DEFAULT')), true , false,false, NULL, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE); - $id_carrier = Tools::getValue('id_carrier', $obj->id_carrier); - foreach ($carriers AS $carrier) - if (!$carrier['is_free']) - $carrierArray[] = '*'; - - echo ' -
- '.($obj->id ? '' : '').' -
'.$this->l('Weight ranges').' - -
'; - if (count($carrierArray)) - { - echo ' -

'.$this->l('Carrier to which this range will be applied').'

'; - } - else - echo '
'.$this->l('There isn\'t any carrier available for a weight range.').'
'; - echo ' -
- -
- '.Configuration::get('PS_WEIGHT_UNIT').' * -

'.$this->l('Range start (included)').'

-
- -
- '.Configuration::get('PS_WEIGHT_UNIT').' * -

'.$this->l('Range end (excluded)').'

-
-
- -
-
* '.$this->l('Required field').'
-
-
'; - } -} - - diff --git a/admin-dev/themes/template/helper/form/form.tpl b/admin-dev/themes/template/helper/form/form.tpl index 9fdcde429..ef93b8d8c 100644 --- a/admin-dev/themes/template/helper/form/form.tpl +++ b/admin-dev/themes/template/helper/form/form.tpl @@ -125,6 +125,7 @@ {if isset($input.class)}class="{$input.class}"{/if} {if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} {if isset($input.disabled) && $input.disabled}disabled="disabled"{/if} /> + {if isset($input.suffix)}{$input.suffix}{/if} {if isset($input.hint)}{$input.hint} {/if} {/if} {elseif $input.type == 'select'} diff --git a/controllers/admin/AdminRangeWeightController.php b/controllers/admin/AdminRangeWeightController.php new file mode 100644 index 000000000..731d3b0a3 --- /dev/null +++ b/controllers/admin/AdminRangeWeightController.php @@ -0,0 +1,124 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 6844 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminRangeWeightControllerCore extends AdminController +{ + public function __construct() + { + $this->table = 'range_weight'; + $this->className = 'RangeWeight'; + $this->lang = false; + + $this->addRowAction('edit'); + $this->addRowAction('delete'); + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + $this->fieldsDisplay = array( + 'id_range_weight' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), + 'carrier_name' => array('title' => $this->l('Carrier'), 'align' => 'center', 'width' => 25, 'filter_key' => 'ca!name'), + 'delimiter1' => array('title' => $this->l('From'), 'width' => 86, 'float' => true, 'suffix' => Configuration::get('PS_WEIGHT_UNIT'), 'align' => 'right'), + 'delimiter2' => array('title' => $this->l('To'), 'width' => 86, 'float' => true, 'suffix' => Configuration::get('PS_WEIGHT_UNIT'), 'align' => 'right')); + + $this->_join = 'LEFT JOIN '._DB_PREFIX_.'carrier ca ON (ca.`id_carrier` = a.`id_carrier`)'; + $this->_select = 'ca.`name` AS carrier_name'; + $this->_where = 'AND ca.`deleted` = 0'; + + parent::__construct(); + } + + public function initForm() + { + $carriers = Carrier::getCarriers($this->context->language->id, true , false, false, NULL, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE); + foreach ($carriers AS $key => $carrier) + if ($carrier['is_free']) + unset($carriers[$key]); + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Weight ranges'), + 'image' => '../img/t/AdminRangeWeight.gif' + ), + 'input' => array( + array( + 'type' => 'select', + 'label' => $this->l('Carrier:'), + 'name' => 'id_carrier', + 'required' => false, + 'p' => $this->l('Carrier to which this range will be applied'), + 'options' => array( + 'query' => $carriers, + 'id' => 'id_carrier', + 'name' => 'name' + ), + ), + array( + 'type' => 'text', + 'label' => $this->l('From:'), + 'name' => 'delimiter1', + 'size' => 5, + 'required' => true, + 'suffix' => Configuration::get('PS_WEIGHT_UNIT'), + 'p' => $this->l('Range start (included)'), + ), + array( + 'type' => 'text', + 'label' => $this->l('To:'), + 'name' => 'delimiter2', + 'size' => 5, + 'required' => true, + 'suffix' => Configuration::get('PS_WEIGHT_UNIT'), + 'p' => $this->l('Range end (excluded)'), + ), + ), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ) + ); + + return parent::initForm(); + } + + public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) + { + parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); + if ($this->_list && is_array($this->_list)) + foreach ($this->_list as $key => $list) + if ($list['carrier_name'] == '0') + $this->_list[$key]['carrier_name'] = Configuration::get('PS_SHOP_NAME'); + } + + public function postProcess() + { + if ($this->action == 'save' && Tools::getValue('delimiter1') >= Tools::getValue('delimiter2')) + $this->_errors[] = Tools::displayError('Invalid range'); + else + parent::postProcess(); + } +} + +