From c02982a8f89ccebded1cebc6dabbb7aa94eb27f0 Mon Sep 17 00:00:00 2001 From: rMalie Date: Thu, 16 Feb 2012 14:10:30 +0000 Subject: [PATCH] // Fix default shop associations in helper shop #PSTEST-770 --- .../template/helpers/{ => form}/assoshop.tpl | 2 +- .../default/template/helpers/form/form.tpl | 2 +- classes/helper/Helper.php | 60 ------------- classes/helper/HelperForm.php | 87 ++++++++++++++++--- .../admin/AdminCategoriesController.php | 3 +- controllers/admin/AdminProductsController.php | 2 +- modules/blocklayered/blocklayered.php | 4 +- modules/blocklink/blocklink.php | 2 +- 8 files changed, 81 insertions(+), 81 deletions(-) rename admin-dev/themes/default/template/helpers/{ => form}/assoshop.tpl (98%) diff --git a/admin-dev/themes/default/template/helpers/assoshop.tpl b/admin-dev/themes/default/template/helpers/form/assoshop.tpl similarity index 98% rename from admin-dev/themes/default/template/helpers/assoshop.tpl rename to admin-dev/themes/default/template/helpers/form/assoshop.tpl index 73c9c940a..005e658e1 100644 --- a/admin-dev/themes/default/template/helpers/assoshop.tpl +++ b/admin-dev/themes/default/template/helpers/form/assoshop.tpl @@ -46,7 +46,7 @@ $().ready(function() { }); // Initialize checkbox - $('.input_shop').each(function(k, v) { + $('.input_group_shop').each(function(k, v) { check_group_shop_status($(v).val()); check_all_shop(); }); diff --git a/admin-dev/themes/default/template/helpers/form/form.tpl b/admin-dev/themes/default/template/helpers/form/form.tpl index a7da07897..4941dd251 100644 --- a/admin-dev/themes/default/template/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/helpers/form/form.tpl @@ -291,7 +291,7 @@ {assign var=groups value=$input.values} {include file='helpers/form/form_group.tpl'} {elseif $input.type == 'shop' OR $input.type == 'group_shop'} - {include file='helpers/assoshop.tpl' input=$input fields_value=$fields_value} + {$input.html} {elseif $input.type == 'categories'} {include file='helpers/form/form_category.tpl' categories=$input.values} {elseif $input.type == 'categories_select'} diff --git a/classes/helper/Helper.php b/classes/helper/Helper.php index 2e9c2660a..7938ab971 100755 --- a/classes/helper/Helper.php +++ b/classes/helper/Helper.php @@ -309,66 +309,6 @@ class HelperCore return Translate::getAdminTranslation($string, get_class($this), $addslashes, $htmlentities); } - /** - * Render an area to determinate shop association - * - * @param string $type 'shop' or 'group_shop' - * - * @return string - */ - public function renderAssoShop($type = 'shop') - { - if (!Shop::isFeatureActive()) - return; - - if ($type != 'shop' && $type != 'group_shop') - $type = 'shop'; - - $assos = array(); - if ((int)$this->id) - { - $sql = 'SELECT `id_'.$type.'`, `'.bqSQL($this->identifier).'` - FROM `'._DB_PREFIX_.bqSQL($this->table).'_'.$type.'` - WHERE `'.bqSQL($this->identifier).'` = '.(int)$this->id; - - foreach (Db::getInstance()->executeS($sql) as $row) - $assos[$row['id_'.$type]] = $row['id_'.$type]; - } - else - { - switch (Context::shop()) - { - case Shop::CONTEXT_SHOP : - $assos[$this->context->shop->id] = $this->context->shop->id; - break; - - case Shop::CONTEXT_GROUP : - foreach (Shop::getShops(false, $this->context->shop->getGroupID(), true) as $id_shop) - $assos[$id_shop] = $id_shop; - break; - - default : - foreach (Shop::getShops(false, null, true) as $id_shop) - $assos[$id_shop] = $id_shop; - break; - } - } - - $tpl = $this->createTemplate('helpers/assoshop.tpl'); - $tpl->assign(array( - 'input' => array( - 'type' => $type, - 'values' => Shop::getTree(), - ), - 'fields_value' => array( - 'shop' => $assos - ), - 'form_id' => $this->id, - 'table' => $this->table - )); - return $tpl->fetch(); - } - /** * Render a form with potentials required fields * diff --git a/classes/helper/HelperForm.php b/classes/helper/HelperForm.php index e1ee2de18..95382c79f 100644 --- a/classes/helper/HelperForm.php +++ b/classes/helper/HelperForm.php @@ -72,21 +72,15 @@ class HelperFormCore extends Helper if ($this->submit_action == '') $this->submit_action = 'submitAdd'.$this->table; - if (isset($this->fields_form[0]['form']['asso_shop']) && Shop::isFeatureActive()) - if ($this->fields_form[0]['asso_shop'] == 'group') - $asso_shop = $this->renderAssoShop('group_shop'); - else if ($this->fields_form[0]['form']['asso_shop'] == 'shop') - $asso_shop = $this->renderAssoShop(); - $this->context->controller->addJS(_PS_JS_DIR_.'form.js'); $categories = true; $color = true; $date = true; $tinymce = true; - foreach ($this->fields_form as $fieldset_key => $fieldset) + foreach ($this->fields_form as $fieldset_key => &$fieldset) if (isset($fieldset['form']['input'])) - foreach ($fieldset['form']['input'] as $key => $params) + foreach ($fieldset['form']['input'] as $key => &$params) { // If the condition is not met, the field will not be displayed if (isset($params['condition']) && !$params['condition']) @@ -108,7 +102,8 @@ class HelperFormCore extends Helper $this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js'); $categories = false; } - break; + break; + case 'color': if ($color) { @@ -116,14 +111,16 @@ class HelperFormCore extends Helper $this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/jquery.colorpicker.js'); $color = false; } - break; + break; + case 'date': if ($date) { $this->context->controller->addJqueryUI('ui.datepicker'); $date = false; } - break; + break; + case 'textarea': if ($tinymce) { @@ -137,7 +134,12 @@ class HelperFormCore extends Helper $this->context->controller->addJS(_PS_JS_DIR_.'tinymce.inc.js'); $tinymce = false; } - break; + break; + + case 'shop' : + case 'group_shop' : + $params['html'] = $this->renderAssoShop($params['type']); + break; } } @@ -162,7 +164,6 @@ class HelperFormCore extends Helper 'vat_number' => file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php'), 'module_dir' => _MODULE_DIR_, 'contains_states' => (isset($this->fields_value['id_country']) && isset($this->fields_value['id_state'])) ? Country::containsStates($this->fields_value['id_country']) : null, - 'asso_shop' => isset($asso_shop) ? $asso_shop : null )); return parent::generate(); } @@ -180,4 +181,64 @@ class HelperFormCore extends Helper return false; } + + /** + * Render an area to determinate shop association + * + * @param string $type 'shop' or 'group_shop' + * + * @return string + */ + public function renderAssoShop($type = 'shop') + { + if (!Shop::isFeatureActive()) + return; + + if ($type != 'shop' && $type != 'group_shop') + $type = 'shop'; + + $assos = array(); + if ((int)$this->id) + { + $sql = 'SELECT `id_'.$type.'`, `'.bqSQL($this->identifier).'` + FROM `'._DB_PREFIX_.bqSQL($this->table).'_'.$type.'` + WHERE `'.bqSQL($this->identifier).'` = '.(int)$this->id; + + foreach (Db::getInstance()->executeS($sql) as $row) + $assos[$row['id_'.$type]] = $row['id_'.$type]; + } + else + { + switch (Context::shop()) + { + case Shop::CONTEXT_SHOP : + $assos[$this->context->shop->id] = $this->context->shop->id; + break; + + case Shop::CONTEXT_GROUP : + foreach (Shop::getShops(false, $this->context->shop->getGroupID(), true) as $id_shop) + $assos[$id_shop] = $id_shop; + break; + + default : + foreach (Shop::getShops(false, null, true) as $id_shop) + $assos[$id_shop] = $id_shop; + break; + } + } + + $tpl = $this->createTemplate('assoshop.tpl'); + $tpl->assign(array( + 'input' => array( + 'type' => $type, + 'values' => Shop::getTree(), + ), + 'fields_value' => array( + 'shop' => $assos + ), + 'form_id' => $this->id, + 'table' => $this->table + )); + return $tpl->fetch(); + } } diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 63b89c1b3..82cf4ff67 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -421,11 +421,10 @@ class AdminCategoriesControllerCore extends AdminController ) ); if (Shop::isFeatureActive()) - $this->fields_form['input'][] = array( + $this->fields_form['form'][] = array( 'type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso', - 'values' => Shop::getTree() ); // remove category tree and radio button "is_root_category" if this category has the root category as parent category to avoid any conflict if ($this->_category->id_parent == Category::getTopCategory()->id && Tools::isSubmit('updatecategory')) diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 712450d6f..9ebeeec89 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2503,7 +2503,7 @@ class AdminProductsControllerCore extends AdminController // Multishop block $data->assign('feature_shop_active', Shop::isFeatureActive()); - $helper = new Helper(); + $helper = new HelperForm(); if ($this->object && $this->object->id) $helper->id = $this->object->id; else diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index 1aebfad01..38dc1ec4a 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -1636,7 +1636,7 @@ class BlockLayered extends Module if (version_compare(_PS_VERSION_,'1.5','>')) { - $helper = new Helper(); + $helper = new HelperForm(); $helper->id = null; $helper->table = 'layered_filter'; $helper->identifier = 'id_layered_filter'; @@ -3528,7 +3528,7 @@ class BlockLayered extends Module { if (Shop::isFeatureActive() && $this->context->shop->getContextType() != Shop::CONTEXT_ALL) { - $helper = new Helper(); + $helper = new HelperForm(); $helper->id = (int)$id_layered_filter; $helper->table = 'layered_filter'; $helper->identifier = 'id_layered_filter'; diff --git a/modules/blocklink/blocklink.php b/modules/blocklink/blocklink.php index 2d35acaa6..3c2ede4b6 100644 --- a/modules/blocklink/blocklink.php +++ b/modules/blocklink/blocklink.php @@ -320,7 +320,7 @@ class BlockLink extends Module
'; if (Shop::isFeatureActive()) { - $helper = new Helper(); + $helper = new HelperForm(); $helper->id = (int)Tools::getValue('id_link'); $helper->table = 'blocklink'; $helper->identifier = 'id_blocklink';