// BO: Remove category filter by select in product page and refactor Helper::renderAdminCategorieTree()
This commit is contained in:
+75
-16
@@ -97,10 +97,40 @@ class HelperCore
|
|||||||
return $this->tpl->fetch();
|
return $this->tpl->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated since 1.5 - use Helper::renderCategoryTree() instead
|
||||||
|
* @static
|
||||||
|
* @param $translations
|
||||||
|
* @param array $selected_cat
|
||||||
|
* @param string $input_name
|
||||||
|
* @param bool $use_radio
|
||||||
|
* @param bool $use_search
|
||||||
|
* @param array $disabled_categories
|
||||||
|
* @param bool $use_in_popup
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function renderAdminCategorieTree($translations,
|
||||||
|
$selected_cat = array(),
|
||||||
|
$input_name = 'categoryBox',
|
||||||
|
$use_radio = false,
|
||||||
|
$use_search = false,
|
||||||
|
$disabled_categories = array(),
|
||||||
|
$use_in_popup = false)
|
||||||
|
{
|
||||||
|
$helper = new Helper();
|
||||||
|
if (isset($translations['Root']))
|
||||||
|
$root = $translations['Root'];
|
||||||
|
else if (isset($translations['Home']))
|
||||||
|
$root = array('name' => $translations['Home'], 'id_category' => 1);
|
||||||
|
else
|
||||||
|
throw new PrestaShopException('Missing root category parameter.');
|
||||||
|
|
||||||
|
return $helper->renderCategoryTree($root, $selected_cat, $input_name, $use_radio, $use_search, $disabled_categories, $use_in_popup);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param type $trads values of translations keys
|
* @param array $root array with the name and ID of the tree root category, if null the Shop's root category will be used
|
||||||
* For the moment, translation are not automatic
|
|
||||||
* @param type $selected_cat array of selected categories
|
* @param type $selected_cat array of selected categories
|
||||||
* Format
|
* Format
|
||||||
* Array
|
* Array
|
||||||
@@ -118,18 +148,42 @@ class HelperCore
|
|||||||
* [link_rewrite] => home
|
* [link_rewrite] => home
|
||||||
* )
|
* )
|
||||||
* )
|
* )
|
||||||
* @param type $input_name name of input
|
* @param string $input_name name of input
|
||||||
|
* @param bool $use_radio use radio tree or checkbox tree
|
||||||
|
* @param bool $use_search display a find category search box
|
||||||
|
* @param array $disabled_categories
|
||||||
|
* @param bool $use_in_popup
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function renderAdminCategorieTree($trads, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false, $disabled_categories = array(), $use_in_popup = false)
|
public function renderCategoryTree($root = null,
|
||||||
|
$selected_cat = array(),
|
||||||
|
$input_name = 'categoryBox',
|
||||||
|
$use_radio = false,
|
||||||
|
$use_search = false,
|
||||||
|
$disabled_categories = array(),
|
||||||
|
$use_in_popup = false)
|
||||||
{
|
{
|
||||||
|
$translations = array(
|
||||||
|
'selected' => $this->l('selected'),
|
||||||
|
'Collapse All' => $this->l('Collapse All'),
|
||||||
|
'Expand All' => $this->l('Expand All'),
|
||||||
|
'Check All' => $this->l('Check All'),
|
||||||
|
'Uncheck All' => $this->l('Uncheck All'),
|
||||||
|
'search' => $this->l('Find a category')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$root)
|
||||||
|
{
|
||||||
|
$root_category = Category::getRootCategory();
|
||||||
|
$root = array('name' => $root_category->name, 'id_category' => $root_category->id);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$use_radio)
|
if (!$use_radio)
|
||||||
$input_name = $input_name.'[]';
|
$input_name = $input_name.'[]';
|
||||||
|
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
|
|
||||||
$context->controller->addCSS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.css');
|
$context->controller->addCSS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.css');
|
||||||
|
|
||||||
$context->controller->addJs(array(
|
$context->controller->addJs(array(
|
||||||
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.js',
|
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.js',
|
||||||
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js',
|
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js',
|
||||||
@@ -152,8 +206,8 @@ class HelperCore
|
|||||||
else
|
else
|
||||||
$html .= 'var selectedCat = "";';
|
$html .= 'var selectedCat = "";';
|
||||||
$html .= '
|
$html .= '
|
||||||
var selectedLabel = \''.$trads['selected'].'\';
|
var selectedLabel = \''.$translations['selected'].'\';
|
||||||
var home = \''.$trads['Root']['name'].'\';
|
var home = \''.$root['name'].'\';
|
||||||
var use_radio = '.(int)$use_radio.';';
|
var use_radio = '.(int)$use_radio.';';
|
||||||
if (!$use_in_popup)
|
if (!$use_in_popup)
|
||||||
$html .= '
|
$html .= '
|
||||||
@@ -166,15 +220,15 @@ class HelperCore
|
|||||||
|
|
||||||
$html .= '
|
$html .= '
|
||||||
<div class="category-filter">
|
<div class="category-filter">
|
||||||
<span><a href="#" id="collapse_all" >'.$trads['Collapse All'].'</a>
|
<span><a href="#" id="collapse_all" >'.$translations['Collapse All'].'</a>
|
||||||
| </span>
|
| </span>
|
||||||
<span><a href="#" id="expand_all" >'.$trads['Expand All'].'</a>
|
<span><a href="#" id="expand_all" >'.$translations['Expand All'].'</a>
|
||||||
'.(!$use_radio ? '
|
'.(!$use_radio ? '
|
||||||
|</span>
|
|</span>
|
||||||
<span> <a href="#" id="check_all" >'.$trads['Check All'].'</a>
|
<span> <a href="#" id="check_all" >'.$translations['Check All'].'</a>
|
||||||
|</span>
|
|</span>
|
||||||
<span><a href="#" id="uncheck_all" >'.$trads['Uncheck All'].'</a>|</span>
|
<span><a href="#" id="uncheck_all" >'.$translations['Uncheck All'].'</a>|</span>
|
||||||
' : '').($use_search ? '<span>'.$trads['search'].' : <input type="text" name="search_cat" id="search_cat"></span>' : '').'
|
' : '').($use_search ? '<span>'.$translations['search'].' : <input type="text" name="search_cat" id="search_cat"></span>' : '').'
|
||||||
</div>
|
</div>
|
||||||
';
|
';
|
||||||
|
|
||||||
@@ -185,7 +239,7 @@ class HelperCore
|
|||||||
if (is_array($cat))
|
if (is_array($cat))
|
||||||
{
|
{
|
||||||
$disabled = in_array($cat['id_category'], $disabled_categories);
|
$disabled = in_array($cat['id_category'], $disabled_categories);
|
||||||
if ($cat['id_category'] != $trads['Root']['id_category'])
|
if ($cat['id_category'] != $root['id_category'])
|
||||||
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat['id_category'].'" >';
|
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat['id_category'].'" >';
|
||||||
else
|
else
|
||||||
$home_is_selected = true;
|
$home_is_selected = true;
|
||||||
@@ -193,7 +247,7 @@ class HelperCore
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$disabled = in_array($cat, $disabled_categories);
|
$disabled = in_array($cat, $disabled_categories);
|
||||||
if ($cat != $trads['Root']['id_category'])
|
if ($cat != $root['id_category'])
|
||||||
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat.'" >';
|
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat.'" >';
|
||||||
else
|
else
|
||||||
$home_is_selected = true;
|
$home_is_selected = true;
|
||||||
@@ -201,8 +255,13 @@ class HelperCore
|
|||||||
}
|
}
|
||||||
$html .= '
|
$html .= '
|
||||||
<ul id="categories-treeview" class="filetree">
|
<ul id="categories-treeview" class="filetree">
|
||||||
<li id="'.$trads['Root']['id_category'].'" class="hasChildren">
|
<li id="'.$root['id_category'].'" class="hasChildren">
|
||||||
<span class="folder"> <input type="'.(!$use_radio ? 'checkbox' : 'radio').'" name="'.$input_name.'" value="'.$trads['Root']['id_category'].'" '.($home_is_selected ? 'checked' : '').' onclick="clickOnCategoryBox($(this));" /> '.$trads['Root']['name'].'</span>
|
<span class="folder">
|
||||||
|
<input type="'.(!$use_radio ? 'checkbox' : 'radio').'" name="'
|
||||||
|
.$input_name.'" value="'.$root['id_category'].'" '
|
||||||
|
.($home_is_selected ? 'checked' : '').' onclick="clickOnCategoryBox($(this));" /> '
|
||||||
|
.$root['name']
|
||||||
|
.'</span>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span class="placeholder"> </span></li>
|
<li><span class="placeholder"> </span></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -80,12 +80,6 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$this->max_file_size = (int)(Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
|
$this->max_file_size = (int)(Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
|
||||||
$this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
|
$this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
|
||||||
|
|
||||||
$categoriesArray = array();
|
|
||||||
$categories = Category::getSimpleCategories($this->context->language->id);
|
|
||||||
|
|
||||||
foreach ($categories AS $categorie)
|
|
||||||
$categoriesArray[$categorie['id_category']] = $categorie['name'];
|
|
||||||
|
|
||||||
$this->fieldsDisplay = array(
|
$this->fieldsDisplay = array(
|
||||||
'id_product' => array(
|
'id_product' => array(
|
||||||
'title' => $this->l('ID'),
|
'title' => $this->l('ID'),
|
||||||
@@ -107,27 +101,24 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
),
|
),
|
||||||
'reference' => array(
|
'reference' => array(
|
||||||
'title' => $this->l('Reference'),
|
'title' => $this->l('Reference'),
|
||||||
'align' => 'center',
|
'align' => 'left',
|
||||||
'width' => 80
|
'width' => 80
|
||||||
),
|
),
|
||||||
'name_category' => array(
|
'name_category' => array(
|
||||||
'title' => $this->l('Category'),
|
'title' => $this->l('Category'),
|
||||||
'width' => 230,
|
'width' => 230,
|
||||||
'type' => 'select',
|
|
||||||
'list' => $categoriesArray,
|
|
||||||
'filter_key' => 'cl!name',
|
'filter_key' => 'cl!name',
|
||||||
'filter_type' => 'int'
|
|
||||||
),
|
),
|
||||||
'price' => array(
|
'price' => array(
|
||||||
'title' => $this->l('Base price'),
|
'title' => $this->l('Base price'),
|
||||||
'width' => 70,
|
'width' => 90,
|
||||||
'type' => 'price',
|
'type' => 'price',
|
||||||
'align' => 'right',
|
'align' => 'right',
|
||||||
'filter_key' => 'a!price'
|
'filter_key' => 'a!price'
|
||||||
),
|
),
|
||||||
'price_final' => array(
|
'price_final' => array(
|
||||||
'title' => $this->l('Final price'),
|
'title' => $this->l('Final price'),
|
||||||
'width' => 70,
|
'width' => 90,
|
||||||
'type' => 'price',
|
'type' => 'price',
|
||||||
'align' => 'right',
|
'align' => 'right',
|
||||||
'havingFilter' => true,
|
'havingFilter' => true,
|
||||||
@@ -1885,27 +1876,11 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$this->getList($this->context->language->id, !$this->context->cookie->__get($this->table.'Orderby') ? 'position' : null, !$this->context->cookie->__get($this->table.'Orderway') ? 'ASC' : null, 0, null, $this->context->shop->getID(true));
|
$this->getList($this->context->language->id, !$this->context->cookie->__get($this->table.'Orderby') ? 'position' : null, !$this->context->cookie->__get($this->table.'Orderway') ? 'ASC' : null, 0, null, $this->context->shop->getID(true));
|
||||||
|
|
||||||
$id_category = Tools::getValue('id_category', 1);
|
$id_category = Tools::getValue('id_category', 1);
|
||||||
|
|
||||||
$root_category = Category::getRootCategory();
|
|
||||||
if (!$root_category->id_category)
|
|
||||||
{
|
|
||||||
$root_category->id_category = 0;
|
|
||||||
$root_category->name = $this->l('Root');
|
|
||||||
}
|
|
||||||
$root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name);
|
|
||||||
|
|
||||||
$translations = array(
|
|
||||||
'Root' => $root_category,
|
|
||||||
'selected' => $this->l('selected'),
|
|
||||||
'Collapse All' => $this->l('Collapse All'),
|
|
||||||
'Expand All' => $this->l('Expand All'),
|
|
||||||
'Check All' => $this->l('Check All'),
|
|
||||||
'Uncheck All' => $this->l('Uncheck All'),
|
|
||||||
'search' => $this->l('Search a category')
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->tpl_list_vars['is_category_filter'] = Tools::getValue('id_category') ? true : false;
|
$this->tpl_list_vars['is_category_filter'] = Tools::getValue('id_category') ? true : false;
|
||||||
$this->tpl_list_vars['category_tree'] = Helper::renderAdminCategorieTree($translations, array($id_category), 'categoryBox', true, false);
|
|
||||||
|
// Generate category selection tree
|
||||||
|
$helper = new Helper();
|
||||||
|
$this->tpl_list_vars['category_tree'] = $helper->renderCategoryTree(null, array($id_category), 'categoryBox', true, false);
|
||||||
|
|
||||||
// used to build the new url when changing category
|
// used to build the new url when changing category
|
||||||
$this->tpl_list_vars['base_url'] = preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token;
|
$this->tpl_list_vars['base_url'] = preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token;
|
||||||
|
|||||||
Reference in New Issue
Block a user