// Fix default shop associations in helper shop #PSTEST-770

This commit is contained in:
rMalie
2012-02-16 14:10:30 +00:00
parent e9d113dac7
commit c02982a8f8
8 changed files with 81 additions and 81 deletions
@@ -46,7 +46,7 @@ $().ready(function() {
}); });
// Initialize checkbox // Initialize checkbox
$('.input_shop').each(function(k, v) { $('.input_group_shop').each(function(k, v) {
check_group_shop_status($(v).val()); check_group_shop_status($(v).val());
check_all_shop(); check_all_shop();
}); });
@@ -291,7 +291,7 @@
{assign var=groups value=$input.values} {assign var=groups value=$input.values}
{include file='helpers/form/form_group.tpl'} {include file='helpers/form/form_group.tpl'}
{elseif $input.type == 'shop' OR $input.type == 'group_shop'} {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'} {elseif $input.type == 'categories'}
{include file='helpers/form/form_category.tpl' categories=$input.values} {include file='helpers/form/form_category.tpl' categories=$input.values}
{elseif $input.type == 'categories_select'} {elseif $input.type == 'categories_select'}
-60
View File
@@ -309,66 +309,6 @@ class HelperCore
return Translate::getAdminTranslation($string, get_class($this), $addslashes, $htmlentities); 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 * Render a form with potentials required fields
* *
+74 -13
View File
@@ -72,21 +72,15 @@ class HelperFormCore extends Helper
if ($this->submit_action == '') if ($this->submit_action == '')
$this->submit_action = 'submitAdd'.$this->table; $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'); $this->context->controller->addJS(_PS_JS_DIR_.'form.js');
$categories = true; $categories = true;
$color = true; $color = true;
$date = true; $date = true;
$tinymce = true; $tinymce = true;
foreach ($this->fields_form as $fieldset_key => $fieldset) foreach ($this->fields_form as $fieldset_key => &$fieldset)
if (isset($fieldset['form']['input'])) 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 the condition is not met, the field will not be displayed
if (isset($params['condition']) && !$params['condition']) 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'); $this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js');
$categories = false; $categories = false;
} }
break; break;
case 'color': case 'color':
if ($color) if ($color)
{ {
@@ -116,14 +111,16 @@ class HelperFormCore extends Helper
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/jquery.colorpicker.js'); $this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/jquery.colorpicker.js');
$color = false; $color = false;
} }
break; break;
case 'date': case 'date':
if ($date) if ($date)
{ {
$this->context->controller->addJqueryUI('ui.datepicker'); $this->context->controller->addJqueryUI('ui.datepicker');
$date = false; $date = false;
} }
break; break;
case 'textarea': case 'textarea':
if ($tinymce) if ($tinymce)
{ {
@@ -137,7 +134,12 @@ class HelperFormCore extends Helper
$this->context->controller->addJS(_PS_JS_DIR_.'tinymce.inc.js'); $this->context->controller->addJS(_PS_JS_DIR_.'tinymce.inc.js');
$tinymce = false; $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'), 'vat_number' => file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php'),
'module_dir' => _MODULE_DIR_, '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, '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(); return parent::generate();
} }
@@ -180,4 +181,64 @@ class HelperFormCore extends Helper
return false; 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();
}
} }
@@ -421,11 +421,10 @@ class AdminCategoriesControllerCore extends AdminController
) )
); );
if (Shop::isFeatureActive()) if (Shop::isFeatureActive())
$this->fields_form['input'][] = array( $this->fields_form['form'][] = array(
'type' => 'shop', 'type' => 'shop',
'label' => $this->l('Shop association:'), 'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso', '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 // 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')) if ($this->_category->id_parent == Category::getTopCategory()->id && Tools::isSubmit('updatecategory'))
@@ -2503,7 +2503,7 @@ class AdminProductsControllerCore extends AdminController
// Multishop block // Multishop block
$data->assign('feature_shop_active', Shop::isFeatureActive()); $data->assign('feature_shop_active', Shop::isFeatureActive());
$helper = new Helper(); $helper = new HelperForm();
if ($this->object && $this->object->id) if ($this->object && $this->object->id)
$helper->id = $this->object->id; $helper->id = $this->object->id;
else else
+2 -2
View File
@@ -1636,7 +1636,7 @@ class BlockLayered extends Module
if (version_compare(_PS_VERSION_,'1.5','>')) if (version_compare(_PS_VERSION_,'1.5','>'))
{ {
$helper = new Helper(); $helper = new HelperForm();
$helper->id = null; $helper->id = null;
$helper->table = 'layered_filter'; $helper->table = 'layered_filter';
$helper->identifier = 'id_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) if (Shop::isFeatureActive() && $this->context->shop->getContextType() != Shop::CONTEXT_ALL)
{ {
$helper = new Helper(); $helper = new HelperForm();
$helper->id = (int)$id_layered_filter; $helper->id = (int)$id_layered_filter;
$helper->table = 'layered_filter'; $helper->table = 'layered_filter';
$helper->identifier = 'id_layered_filter'; $helper->identifier = 'id_layered_filter';
+1 -1
View File
@@ -320,7 +320,7 @@ class BlockLink extends Module
<div class="margin-form"><input type="checkbox" name="newWindow" id="newWindow" '.((isset($links) && $links['new_window']) ? 'checked="checked"' : '').' /></div>'; <div class="margin-form"><input type="checkbox" name="newWindow" id="newWindow" '.((isset($links) && $links['new_window']) ? 'checked="checked"' : '').' /></div>';
if (Shop::isFeatureActive()) if (Shop::isFeatureActive())
{ {
$helper = new Helper(); $helper = new HelperForm();
$helper->id = (int)Tools::getValue('id_link'); $helper->id = (int)Tools::getValue('id_link');
$helper->table = 'blocklink'; $helper->table = 'blocklink';
$helper->identifier = 'id_blocklink'; $helper->identifier = 'id_blocklink';