Jump to content

[Bug?] Categories block doesn't load at subcategory page


Recommended Posts

Hi,

 

I've noticed that the block categories doesn't load at category pages showing subcategories and products.

 

I've checked the html to be sure that it is hidden, but no. I've checked exceptions too and it should appear.

 

Hi rinzlerx64, can you explain the issue more? I'm a bit confused as to how to reproduce it. Thanks for the message! I will do my best to help. 

  • Like 1
Link to comment
Share on other sites

Hi Benjamin,

 

Thanks for you answer! I have configured my category tree like this:

. Home

   .Products

      .Category of products

         .Product

 

 

The problem is that when category of products are diplayed the block category module hooked in left column disappears, and I mean that it isn't even loaded (in some case I've read it could be hidden by css). I've checked the hook in this page and it's ok, CMS block hooked there is loaded and displayed.
I've also checked the module's exceptions and there is no exception that could be applied in this page.

I'm kind of stuck there, thanks for your help!    

Link to comment
Share on other sites

  • 3 weeks later...

Same here... all the HMTL code in the block is there but the <li> completing  the menu list... so it is including de module on that hook, but it isnt filling the <ul> list with the subcategories... I tried stick it up on the header.tpl, but even though. It seems that once your are on the category page, it can´t find any other on the store.
Terribly stuck here also, using PS 1.6.0.5

  • Like 1
Link to comment
Share on other sites

if subcategory page hasn't got any subcategories to display, block will not appear.

this is how this module works in prestashop 1.6

Thanks Vekia, I understand that... but is there any way, or trick...  to keep the list of Main Categories diplayed all the time? including when you are inside one the categories? I tried to replicate or trick the smarty code in many ways on the .tpl files... but no success.

I wouldnt like to go nuts trying to find the function on the core, because even if I find it, I´m afraid that it wont work unles I chage a fare few of functions.. no only that use on the filling the <li>...

 

Link to comment
Share on other sites

you can use code of module that is a part of block categories module from 1.5 version

 

just copy code of hookDisplayLeftColumn and hookDisplayRightColumn functions.

and replace this code in your blockcategories (use code from 1.5 in 1.6)

Link to comment
Share on other sites

As you wish

here it is:

replace original code with:

(only functions that i pasted below)

	public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0)
	{
		if (is_null($id_category))
			$id_category = $this->context->shop->getCategory();

		$children = array();
		if (isset($resultParents[$id_category]) && count($resultParents[$id_category]) && ($maxDepth == 0 || $currentDepth < $maxDepth))
			foreach ($resultParents[$id_category] as $subcat)
				$children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
		if (!isset($resultIds[$id_category]))
			return false;
		$return = array('id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
					 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
					 'children' => $children);
		return $return;
	}

	public function hookLeftColumn($params)
	{	
		if (!$this->isCached('blockcategories.tpl', $this->getCacheId()))
		{
			// Get all groups for this customer and concatenate them as a string: "1,2,3..."
			$groups = implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id));
			$maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
			if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
				SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
				FROM `'._DB_PREFIX_.'category` c
				INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').')
				INNER JOIN `'._DB_PREFIX_.'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = '.(int)$this->context->shop->id.')
				WHERE (c.`active` = 1 OR c.`id_category` = '.(int)Configuration::get('PS_HOME_CATEGORY').')
				AND c.`id_category` != '.(int)Configuration::get('PS_ROOT_CATEGORY').'
				'.((int)$maxdepth != 0 ? ' AND `level_depth` <= '.(int)$maxdepth : '').'
				AND c.id_category IN (SELECT id_category FROM `'._DB_PREFIX_.'category_group` WHERE `id_group` IN ('.pSQL($groups).'))
				ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')))
				return;

			$resultParents = array();
			$resultIds = array();
			$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);

			foreach ($result as &$row)
			{
				$resultParents[$row['id_parent']][] = &$row;
				$resultIds[$row['id_category']] = &$row;
			}

			$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
			unset($resultParents, $resultIds);

			$this->smarty->assign('blockCategTree', $blockCategTree);

			if (file_exists(_PS_THEME_DIR_.'modules/blockcategories/blockcategories.tpl'))
				$this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
			else
				$this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
			$this->smarty->assign('isDhtml', $isDhtml);
		}

		$id_category = (int)Tools::getValue('id_category');
		$id_product = (int)Tools::getValue('id_product');
		
		if (Tools::isSubmit('id_category'))
		{
			$this->context->cookie->last_visited_category = (int)$id_category;
			$this->smarty->assign('currentCategoryId', $this->context->cookie->last_visited_category);
		}

		if (Tools::isSubmit('id_product'))
		{
			if (!isset($this->context->cookie->last_visited_category)
				|| !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category)))
				|| !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop))
			{
				$product = new Product((int)$id_product);
				if (isset($product) && Validate::isLoadedObject($product))
					$this->context->cookie->last_visited_category = (int)$product->id_category_default;
			}
			$this->smarty->assign('currentCategoryId', (int)$this->context->cookie->last_visited_category);
		}

		$display = $this->display(__FILE__, 'blockcategories.tpl', $this->getCacheId());
		return $display;
	}

	protected function getCacheId($name = null)
	{
		parent::getCacheId($name);

		$groups = implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id));
		$id_product = (int)Tools::getValue('id_product', 0);
		$id_category = (int)Tools::getValue('id_category', 0);
		$id_lang = (int)$this->context->language->id;
		return 'blockcategories|'.(int)Tools::usingSecureMode().'|'.$this->context->shop->id.'|'.$groups.'|'.$id_lang.'|'.$id_product.'|'.$id_category;
	}

	public function hookFooter($params)
	{
		// Get all groups for this customer and concatenate them as a string: "1,2,3..."
		if (!$this->isCached('blockcategories_footer.tpl', $this->getCacheId()))
		{
			$maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
			$groups = implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id));
			if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
				SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
				FROM `'._DB_PREFIX_.'category` c
				'.Shop::addSqlAssociation('category', 'c').'
				LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').')
				LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
				WHERE (c.`active` = 1 OR c.`id_category` = 1)
				'.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').'
				AND cg.`id_group` IN ('.pSQL($groups).')
				ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'category_shop.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')))
				return;
			$resultParents = array();
			$resultIds = array();

			foreach ($result as &$row)
			{
				$resultParents[$row['id_parent']][] = &$row;
				$resultIds[$row['id_category']] = &$row;
			}
			//$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMNS_FOOTER');
			$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER');
			if (!$nbrColumns)
				$nbrColumns = 3;
			$numberColumn = abs(count($result) / $nbrColumns);
			$widthColumn = floor(100 / $nbrColumns);
			$this->smarty->assign('numberColumn', $numberColumn);
			$this->smarty->assign('widthColumn', $widthColumn);

			$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
			unset($resultParents, $resultIds);

			$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);

			$id_category = (int)Tools::getValue('id_category');
			$id_product = (int)Tools::getValue('id_product');

			if (Tools::isSubmit('id_category'))
			{
				$this->context->cookie->last_visited_category = $id_category;
				$this->smarty->assign('currentCategoryId', $this->context->cookie->last_visited_category);
			}
			if (Tools::isSubmit('id_product'))
			{
				if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category))))
				{
					$product = new Product($id_product);
					if (isset($product) && Validate::isLoadedObject($product))
						$this->context->cookie->last_visited_category = (int)($product->id_category_default);
				}
				$this->smarty->assign('currentCategoryId', (int)($this->context->cookie->last_visited_category));
			}
			$this->smarty->assign('blockCategTree', $blockCategTree);

			if (file_exists(_PS_THEME_DIR_.'modules/blockcategories/blockcategories_footer.tpl'))
				$this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
			else
				$this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
			$this->smarty->assign('isDhtml', $isDhtml);
		}
		$display = $this->display(__FILE__, 'blockcategories_footer.tpl', $this->getCacheId());

		return $display;
	}

	public function hookRightColumn($params)
	{
		return $this->hookLeftColumn($params);
	}

	public function hookHeader()
	{
		$this->context->controller->addJS(_THEME_JS_DIR_.'tools/treeManagement.js');
		$this->context->controller->addCSS(($this->_path).'blockcategories.css', 'all');
	}

	private function _clearBlockcategoriesCache()
	{
		$this->_clearCache('blockcategories.tpl');
		$this->_clearCache('blockcategories_footer.tpl');
	}

	public function hookCategoryAddition($params)
	{
		$this->_clearBlockcategoriesCache();
	}

	public function hookCategoryUpdate($params)
	{
		$this->_clearBlockcategoriesCache();
	}

	public function hookCategoryDeletion($params)
	{
		$this->_clearBlockcategoriesCache();
	}

	public function hookActionAdminMetaControllerUpdate_optionsBefore($params)
	{
		$this->_clearBlockcategoriesCache();
	}
Link to comment
Share on other sites

Hi Vekia, I really appreciate your help... Unfortunately i didnt work for me. I´ve replaced those functions in the blockcategories.php inside my theme and it does nothing. Still coming out like this on the category page:

<div id="categories_block_left" class="demo-container block">
	<div class="tptn-vertical-mega-menu">
		<ul id="mega-1" class="menu right">
                </ul>
	</div>
</div>

Looks like the internal core doesnt find the categories on that level... it might need a much more serious surgery in PS1.6 brains!!

 

Link to comment
Share on other sites

  • 2 weeks later...

in blockcategories.tpl there is something like : 

<h2 class="title_block">
		{if isset($currentCategory)}
			{$currentCategory->name|escape}
		{else}
			{l s='Categories' mod='blockcategories'}
		{/if}

but it doesn't work like that...

 

at first we modify php file and title stay permanent "category" although in which category we are, why must modify tpl file ?!

 

Can you help!?!

 

Respect Vekia! 

Edited by robycrazy (see edit history)
Link to comment
Share on other sites

 

 

code that i suggested to use will display currently viewed category name instead of "CATEGORY"this is not what you expect?

 

this is exactly what i want, but its not working like that... or i put the code at wrong place ..  :unsure:

Link to comment
Share on other sites

Hi guys... Sorry but you are discussing a completely different thing that what we started here and we are still missing a solution for the original post.
Please open a new topic for it if you still need to go on with that. In this one we were trying to fix another thing... and at the end it will get closed without a fix for the original problem. Thanx

 

Still couldnt find a way to display the listy of categories on that page and clock is ticking. Could anybody come back to the topic and gimme some ideas?

Vekia, I tried what you suggested and still not working... is there a way to wirte the SQL query or function, and bring the list on your own? Do I explain myself?

 

Thanx

Link to comment
Share on other sites

TinoCas - the topic is  Categories block doesn't load at subcategory pageand the the solution for that is posted by VEKIA - #10. It works fine!

And we discuss a problem connected with this showing of category block!!!!

Link to comment
Share on other sites

 Thank you Vekia. It working! :-) 

For those, where is not working. Just open file ./modules/blockcategories/blockcategories.php and change only functions, what Vekia sends. Or if you are not familiar with PHP, just unzip this file http://tomasbenda.cz/download/blockcategories.zip and exchange it for original file, which is in on your FTP here ./modules/blockcategories/blockcategories.php. It worked for Prestashop version 1.6.0.6.

But before that backup your original blockcategories.php file, if will doesnt work for you.

Link to comment
Share on other sites

  • 2 weeks later...

 Thank you Vekia. It working! :-) 

For those, where is not working. Just open file ./modules/blockcategories/blockcategories.php and change only functions, what Vekia sends. Or if you are not familiar with PHP, just unzip this file http://tomasbenda.cz/download/blockcategories.zip and exchange it for original file, which is in on your FTP here ./modules/blockcategories/blockcategories.php. It worked for Prestashop version 1.6.0.6.

But before that backup your original blockcategories.php file, if will doesnt work for you.

 

I replace original blockcategories.php file - and it works very well, but for one day... Today i open my website and situation is the same - category block is only showed on category tab... Prestashop 1.6.0.6

Edited by digites (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

Hi Friends,

 

Even i am also having the same issue, actually category block is displaying in all pages except list of products page. If i open any category then products are displaying related to the category which i clicked but left side categories are not displaying.

 

Even I am having the issue when I opened any subcategory page.

 

Thanks Inadvance...

Edited by kiran4prestashop (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
  • 1 month later...

I'm on 1.6.0.9 w/ blockcategories 2.8.2 and still have this problem.

I downloaded v1.5 blockcategories.php that was posted and that doesn't work either.

I tried changing category root option to 'home category' as mentioned in above post then the category menu doesn't even display on the left column of a regular category page either.

 

Any resolutions here?

Link to comment
Share on other sites

let's clarify what else you did:

 

1) have you checked exceptions? go to modules> modules and check if module has got exceptions related to appearaing in displayLeftColumn

2) have you tried to remove module files (if not - backup them first!) from /themes/your-theme/modules/blockcategories/

Link to comment
Share on other sites

  • 1 month later...
×
×
  • Create New...