Skip to content

Commit

Permalink
Merge pull request #2696 from jocel1/hotfix-filter-by-categories
Browse files Browse the repository at this point in the history
[-] BO : Fix filter category tree issue
  • Loading branch information
Jérôme Nadaud committed Mar 18, 2015
2 parents 8db15ae + deaffea commit c61fb38
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion admin-dev/themes/default/js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Tree.prototype =
var thatOne = $(this);
$.get(
'ajax-tab.php',
{controller:'AdminProducts',token:currentToken,action:'getCategoryTree',category:category},
{controller:'AdminProducts',token:currentToken,action:'getCategoryTree',type:idTree,category:category},
function(content)
{
thatOne.parent().closest('.tree-folder').find('ul.tree').html(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
</div>
</div>
<script type="text/javascript">
var currentToken="{$token|@addslashes}";
var idTree="{$id|escape:'html':'UTF-8'}";
{if isset($use_checkbox) && $use_checkbox == true}
function checkAllAssociatedCategories($tree)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* International Registered Trademark & Property of PrestaShop SA
*}
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
<label class="tree-item-name">
<span class="tree-item-name">
<input type="radio" name="{$input_name}" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="tree-dot"></i>
{$node['name']}
</label>
<label class="tree-toggler">{$node['name']}</label>
</span>
</li>
9 changes: 9 additions & 0 deletions classes/helper/HelperTreeCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ public function getData()
$selected_categories = $this->getSelectedCategories();
$categories[(int)$this->getRootCategory()] = Category::getChildren($this->getRootCategory(), $this->getLang(), false, $this->getShop()->id);
foreach($selected_categories as $selected_category)
{
$category = new Category($selected_category, $this->getLang(), $this->getShop()->id);
$new_selected_categories[] = $selected_category;
$parents = $category->getParentsCategories($this->getLang());
foreach($parents as $value)
$new_selected_categories[] = $value['id_category'];
}
$new_selected_categories = array_unique($new_selected_categories);
foreach($new_selected_categories as $selected_category)
{
$current_category = Category::getChildren($selected_category, $this->getLang(), false, $this->getShop()->id);
if (!empty($current_category))
Expand Down
8 changes: 7 additions & 1 deletion controllers/admin/AdminProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,14 @@ public function ajaxProcessGetCategoryTree()
$category = Tools::getValue('category', Category::getRootCategory()->id);
$fullTree = Tools::getValue('fullTree', 0);
$selected = Tools::getValue('selected', array());
$type = Tools::getValue('type', '');
if ($type == 'categories-tree')
$use_check_box = false;
else
$use_check_box = true;
$tree = new HelperTreeCategories('subtree_associated_categories');
$tree->setTemplate('subtree_associated_categories.tpl')
->setUseCheckBox(true)
->setUseCheckBox($use_check_box)
->setUseSearch(true)
->setSelectedCategories($selected)
->setFullTree($fullTree)
Expand Down Expand Up @@ -2432,6 +2437,7 @@ public function initContent($token = null)
$tree->setAttribute('is_category_filter', (bool)$this->id_current_category)
->setAttribute('base_url', preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token)
->setInputName('id-category')
->setRootCategory(Configuration::get('PS_ROOT_CATEGORY'))
->setSelectedCategories(array((int)$id_category));
$this->tpl_list_vars['category_tree'] = $tree->render();

Expand Down

0 comments on commit c61fb38

Please sign in to comment.