From 502369ee4f9de2f6ed1aaad96ea727ca82c705f9 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Thu, 13 Oct 2011 09:07:36 +0000 Subject: [PATCH] [*] BO #PSFV-94 : update of the displayform method by helperForm in AdminGroupShopController git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9308 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/themes/template/adminGroupShop.tpl | 113 --------- admin-dev/themes/template/group_shop/form.tpl | 151 +++++++++++ .../template/group_shop/form_import.tpl | 80 ++++++ .../admin/AdminGroupShopController.php | 234 ++++++++++++++---- 4 files changed, 413 insertions(+), 165 deletions(-) delete mode 100644 admin-dev/themes/template/adminGroupShop.tpl create mode 100644 admin-dev/themes/template/group_shop/form.tpl create mode 100644 admin-dev/themes/template/group_shop/form_import.tpl diff --git a/admin-dev/themes/template/adminGroupShop.tpl b/admin-dev/themes/template/adminGroupShop.tpl deleted file mode 100644 index 90919a352..000000000 --- a/admin-dev/themes/template/adminGroupShop.tpl +++ /dev/null @@ -1,113 +0,0 @@ -{* -* 2007-2011 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-3.0.php -* If you did not receive a copy of the license and are unable to -* obtain it through the world-wide-web, please send an email -* to license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 8897 $ -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} - -{if isset($tab_form)} - - - -
- {if $tab_form['id']}{/if} -
- {l s ='GroupShop'} -
{l s ='You can\'t edit GroupShop when you have more than one Shop'}

- -
- -
- -
- - - - -

{l s ='Share customers between shops of this group'}

-
- -
- - - - -

{l s ='Sare stock between shops of this group'}

-
- -
- - - - -

{l s ='Share orders and carts between shops of this group (you can share orders only if you share customers and stock)'}

-
- -
- - - - -

{l s ='Enable or disable shop'}

-
-
- -
-
* {l s ='Required field'}
-

- -
{l s ='Import data from another group shop'} - -
- - {l s ='Duplicate data from group shop'} - -
    - {foreach $tab_form['importData'] as $table => $lang} -
  • - {/foreach} -
-

{l s ='Use this option to associate data (products, modules, etc.) the same way as the selected shop'}

-
- -
-
-
-{/if} - -{$content} \ No newline at end of file diff --git a/admin-dev/themes/template/group_shop/form.tpl b/admin-dev/themes/template/group_shop/form.tpl new file mode 100644 index 000000000..a63907117 --- /dev/null +++ b/admin-dev/themes/template/group_shop/form.tpl @@ -0,0 +1,151 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8971 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if $firstCall} + + +{/if} + +
+ {if $form_id} + + {/if} +
+ {foreach $fields as $key => $field} + {if $key == 'legend'} + + {if isset($field.image)}{$field.title}{/if} + {$field.title} + +
{l s ='You can\'t edit GroupShop when you have more than one Shop'}

+ {elseif $key == 'input'} + {foreach $field as $input} + {if $input.name == 'id_state'} +
+ {/if} + +
+ {if $input.type == 'text'} + + {elseif $input.type == 'select'} + + {elseif $input.type == 'radio'} + {foreach $input.values as $value} + + + {/foreach} + {elseif $input.type == 'textarea'} + + {elseif $input.type == 'checkbox'} + + {/if} + {if isset($input.required) && $input.required} *{/if} + {if isset($input.p)} +

+ {if is_array($input.p)} + {foreach $input.p as $p} + {if is_array($p)} + {$p.text}
+ {else} + {$p}
+ {/if} + {/foreach} + {else} + {$input.p} + {/if} +

+ {/if} +
+ {if $input.name == 'id_state'} +
+ {/if} + {/foreach} + {elseif $key == 'submit'} +
+ +
+ {/if} + {/foreach} + {if $requiredFields} +
* {l s ='Required field'}
+ {/if} +
diff --git a/admin-dev/themes/template/group_shop/form_import.tpl b/admin-dev/themes/template/group_shop/form_import.tpl new file mode 100644 index 000000000..2cb2d0dce --- /dev/null +++ b/admin-dev/themes/template/group_shop/form_import.tpl @@ -0,0 +1,80 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8971 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +
+
+ {foreach $fields as $key => $field} + {if $key == 'legend'} + + {if isset($field.image)}{$field.title}{/if} + {$field.title} + + {elseif $key == 'label'} + + {/if} + + {if $key == 'checkbox'} +
+ + {elseif $key == 'select'} + + {elseif $key == 'allcheckbox'} +
+
    + {foreach $field.values as $key => $label} +
  • + {/foreach} +
+
+ {elseif $key == 'p'} +

{$field}

+
+ {elseif $key == 'submit'} +
+ +
+ {/if} + {/foreach} + {if $requiredFields} +
* {l s ='Required field'}
+ {/if} +
+ + +

+{if $firstCall} + {if $back} + {l s='Back'} + {else} + {l s='Back to list'} + {/if} +
+{/if} \ No newline at end of file diff --git a/controllers/admin/AdminGroupShopController.php b/controllers/admin/AdminGroupShopController.php index f1613bcf2..cc7f5fdd0 100644 --- a/controllers/admin/AdminGroupShopController.php +++ b/controllers/admin/AdminGroupShopController.php @@ -47,7 +47,147 @@ class AdminGroupShopControllerCore extends AdminController 'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'), ); - $this->template = 'adminGroupShop.tpl'; + $enabled = ''.$this->l('Enabled').''; + $disabled = ''.$this->l('Disabled').''; + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('GroupShop') + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('GroupShop name:'), + 'name' => 'name' + ), + array( + 'type' => 'radio', + 'label' => $this->l('Share customers:'), + 'name' => 'share_customer', + 'required' => true, + 'class' => 't', + 'values' => array( + array( + 'id' => 'share_customer_on', + 'value' => 1, + 'label' => $enabled + ), + array( + 'id' => 'share_customer_off', + 'value' => 0, + 'label' => $disabled + ) + ), + 'p' => $this->l('Share customers between shops of this group') + ), + array( + 'type' => 'radio', + 'label' => $this->l('Share stock:'), + 'name' => 'share_stock', + 'required' => true, + 'class' => 't', + 'values' => array( + array( + 'id' => 'share_stock_on', + 'value' => 1, + 'label' => $enabled + ), + array( + 'id' => 'share_stock_off', + 'value' => 0, + 'label' => $disabled + ) + ), + 'p' => $this->l('Share stock between shops of this group') + ), + array( + 'type' => 'radio', + 'label' => $this->l('Share orders:'), + 'name' => 'share_order', + 'required' => true, + 'class' => 't', + 'values' => array( + array( + 'id' => 'share_order_on', + 'value' => 1, + 'label' => $enabled + ), + array( + 'id' => 'share_order_off', + 'value' => 0, + 'label' => $disabled + ) + ), + 'p' => $this->l('Share orders and carts between shops of this group (you can share orders only if you share customers and stock)') + ), + array( + 'type' => 'radio', + 'label' => $this->l('Status:'), + 'name' => 'active', + 'required' => true, + 'class' => 't', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $enabled + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $disabled + ) + ), + 'p' => $this->l('Enable or disable shop') + ) + ), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ) + ); + + $import_data = array( + 'attribute_group' => $this->l('Attribute groups'), + 'attribute' => $this->l('Attributes'), + //'customer_group' => $this->l('Customer groups'), + 'feature' => $this->l('Features'), + 'group' => $this->l('Groups'), + 'manufacturer' => $this->l('Manufacturers'), + 'supplier' => $this->l('Suppliers'), + 'tax_rules_group' => $this->l('Tax rules groups'), + 'zone' => $this->l('Zones'), + ); + + $this->fields_import_form = array( + 'legend' => array( + 'title' => $this->l('Import data from another group shop') + ), + 'label' => $this->l('Duplicate data from group shop'), + 'checkbox' => array( + 'type' => 'checkbox', + 'label' => $this->l('Duplicate data from group shop'), + 'name' => 'useImportData', + 'value' => 1 + ), + 'select' => array( + 'type' => 'select', + 'name' => 'importFromShop', + 'options' => array( + 'query' => Shop::getTree(), + 'name' => 'name' + ) + ), + 'allcheckbox' => array( + 'type' => 'checkbox', + 'values' => $import_data + ), + 'p' => $this->l('Use this option to associate data (products, modules, etc.) the same way as the selected shop'), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ) + ); parent::__construct(); } @@ -68,6 +208,47 @@ class AdminGroupShopControllerCore extends AdminController return parent::postProcess(); } + public function initContent() + { + if (!($obj = $this->loadObject(true))) + return; + + if (Shop::getTotalShops() > 1 && $obj->id) + $disabled = array( + 'share_customer' => true, + 'share_stock' => true, + 'share_order' => true, + 'active' => false + ); + else + $disabled = false; + + $this->context->smarty->assign(array( + 'disabled' => $disabled, + 'checked' => (Tools::getValue('addgroup_shop') !== false) ? true : false, + 'defaultGroup' => Shop::getInstance(Configuration::get('PS_SHOP_DEFAULT'))->getGroupID() + )); + + if ($this->display != 'edit' && $this->display != 'add') + $this->display = 'list'; + + parent::initContent(); + + if ($this->display == 'edit' || $this->display == 'add') + { + $helper = new HelperForm(); + // Check if form template has been overriden + if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'form_import.tpl')) + $helper->tpl = $this->tpl_folder.'form_import.tpl'; + $helper::$currentIndex = self::$currentIndex; + $helper->token = $this->token; + $helper->table = $this->table; + $helper->id = $obj->id; + $helper->fields_value = $this->getFieldsValue($obj); + $this->content .= $helper->generateForm($this->fields_import_form); + } + } + public function afterAdd($new_group_shop) { if (Tools::getValue('useImportData') && ($import_data = Tools::getValue('importData')) && is_array($import_data)) @@ -79,57 +260,6 @@ class AdminGroupShopControllerCore extends AdminController if (Tools::getValue('useImportData') && ($import_data = Tools::getValue('importData')) && is_array($import_data)) $new_group_shop->copyGroupShopData(Tools::getValue('importFromShop'), $import_data); } - - public function displayForm($is_main_tab = true) - { - parent::displayForm($is_main_tab); - - if (!($obj = $this->loadObject(true))) - return; - - if (Shop::getTotalShops() > 1 && $obj->id) - $disabled = 'disabled="disabled"'; - else - $disabled = ''; - - $import_data = array( - 'attribute_group' => $this->l('Attribute groups'), - 'attribute' => $this->l('Attributes'), - //'customer_group' => $this->l('Customer groups'), - 'feature' => $this->l('Features'), - 'group' => $this->l('Groups'), - 'manufacturer' => $this->l('Manufacturers'), - 'supplier' => $this->l('Suppliers'), - 'tax_rules_group' => $this->l('Tax rules groups'), - 'zone' => $this->l('Zones'), - ); - - $this->context->smarty->assign('tab_form', array( - 'current' => self::$currentIndex, - 'table' => $this->table, - 'token' => $this->token, - 'id' => $obj->id, - 'name' => $this->getFieldValue($obj, 'name'), - 'disabled' => $disabled, - 'share_customer' => $this->getFieldValue($obj, 'share_customer') ? true : false, - 'share_stock' => $this->getFieldValue($obj, 'share_stock') ? true : false, - 'share_order' => $this->getFieldValue($obj, 'share_order') ? true : false, - 'active' => $this->getFieldValue($obj, 'active') ? true : false, - 'importData' => $import_data, - 'getTree' => Shop::getTree(), - 'checked' => (Tools::getValue('addgroup_shop') !== false) ? true : false, - 'defaultGroup' => Shop::getInstance(Configuration::get('PS_SHOP_DEFAULT'))->getGroupID() - )); - } - - public function initContent() - { - if ($this->display != 'edit' && $this->display != 'add') - $this->display = 'list'; - - parent::initContent(); - } - }