Jump to content

Breadcrumb problem - wrong path displayed


Recommended Posts

I have a problem with breadcrumbs on the product page, it does not show the real path of the product. Here's how I set it on the backend:

8nOmIQj.jpg

 

Here's how it shows it:

TwFasXR.jpg

 

And here's what my breadcrumb.tpl file contains:

<!-- Breadcrumb -->
{if $page_name != index}
{if isset($smarty.capture.path)}{assign var='path' value=$smarty.capture.path}{/if}

<div id="breadcrumb">
    <ul class="breadcrumb">
        {if $page_name!='product'}
            <li>
            <a href="{$base_dir}" title="{l s='return to Home'}">{l s='Home'} {$navigationPipe|escape:html:'UTF-8'} {l s='Shop'}</a>
            {if isset($path) AND $path}
                {if $page_name!='product'}
                    <span class="divider" {if isset($category) && $category->id_category == 1}style="display:none;"{/if}>
                        {$navigationPipe|escape:html:'UTF-8'}
                    </span>
                {/if}
            {/if}
            </li>
        {/if}
        {if isset($path) AND $path}
            {if !$path|strpos:'span'}
                <li>{$path}</li>
            {else}
                <li class="active">{$path}</li>
            {/if}
        {/if}
    </ul>
</div>
{/if}
<!-- /Breadcrumb -->

Please anybody help me with this. Any advice is helpful.

Thanks!

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

  • 4 weeks later...
  • 3 months later...
  • 1 month later...
  • 2 weeks later...

I have solved the problem in Prestashop 1.6.0.9
 
It is in controllers/ProductController.php
 
We have that :

class ProductControllerCore extends FrontController
{
	/**
	 * Assign template vars related to category
	 */
	protected function assignCategory()
	{
		// Assign category to the template
		if ($this->category !== false && Validate::isLoadedObject($this->category) && $this->category->inShop() && $this->category->isAssociatedToShop())
			$path = Tools::getPath($this->category->id, $this->product->name, true);
		elseif (Category::inShopStatic($this->product->id_category_default, $this->context->shop))
		{
			$this->category = new Category((int)$this->product->id_category_default, (int)$this->context->language->id);
			if (Validate::isLoadedObject( $this->category) &&  $this->category->active &&  $this->category->isAssociatedToShop())
				$path = Tools::getPath((int)$this->product->id_category_default, $this->product->name);
		}
		if (!isset($path) || !$path)
			$path = Tools::getPath((int)$this->context->shop->id_category, $this->product->name);

		$subCategories = array();
		if (Validate::isLoadedObject($this->category))
		{
			$subCategories = $this->category->getSubCategories($this->context->language->id, true);

			// various assignements before Hook::exec
			$this->context->smarty->assign(array(
				'path' => $path,
				'category' => $this->category,
				'subCategories' => $subCategories,
				'id_category_current' => (int)$this->category->id,
				'id_category_parent' => (int)$this->category->id_parent,
				'return_category_name' => Tools::safeOutput($this->category->getFieldByLang('name')),
				'categories' => Category::getHomeCategories($this->context->language->id, true, (int)$this->context->shop->id)
			));
		}
		$this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
	}

}

The problem is :

$path = Tools::getPath($this->category->id, $this->product->name, true);
Instead, you should have :
$this->category = new Category((int)$this->product->id_category_default, (int)$this->context->language->id);
$path = Tools::getPath($this->product->id_category_default, $this->product->name, true);
You can add override/controllers/front/ProductController.php file with this content instead :
class ProductController extends ProductControllerCore
{
	protected function assignCategory()
	{
		// Assign category to the template
		if ($this->category !== false && Validate::isLoadedObject($this->category) && $this->category->inShop() && $this->category->isAssociatedToShop()) {
			// full path
			$this->category = new Category((int)$this->product->id_category_default, (int)$this->context->language->id);
			$path = Tools::getPath($this->product->id_category_default, $this->product->name, true);
		}
		elseif (Category::inShopStatic($this->product->id_category_default, $this->context->shop))
		{
			$this->category = new Category((int)$this->product->id_category_default, (int)$this->context->language->id);
			if (Validate::isLoadedObject( $this->category) &&  $this->category->active &&  $this->category->isAssociatedToShop())
				$path = Tools::getPath((int)$this->product->id_category_default, $this->product->name);
		}
		if (!isset($path) || !$path)
			$path = Tools::getPath((int)$this->context->shop->id_category, $this->product->name);

		$subCategories = array();
		if (Validate::isLoadedObject($this->category))
		{
			$subCategories = $this->category->getSubCategories($this->context->language->id, true);
			// various assignements before Hook::exec
			$this->context->smarty->assign(array(
				'path' => $path,
				'category' => $this->category,
				'subCategories' => $subCategories,
				'id_category_current' => (int)$this->category->id,
				'id_category_parent' => (int)$this->category->id_parent,
				'return_category_name' => Tools::safeOutput($this->category->getFieldByLang('name')),
				'categories' => Category::getHomeCategories($this->context->language->id, true, (int)$this->context->shop->id)
			));
		}
		$this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
	}
}

And it will works.

Link to comment
Share on other sites

  • 2 weeks later...

I still have this problem. My breadcrumb is shown as:

Home > Category > Category > Product

Cant seem to find any problems in the ps_category table.

The fix posted for 1.6.0.9 doesnt work for my 1.6.0.6.

I use a custom theme. But doesnt see how it affects the breadcrumb.tpl as it is the same as default theme breadcrumb.tpl.

Anyone have an idea?

Link to comment
Share on other sites

  • 2 years later...

Try to regenerate positions:

 

Step 1.) Set nright and nleft from categories to null

Db::getInstance()->execute('UPDATE `ps_category` SET `nleft`=0,`nright`=0 WHERE 1');

Step 2.) Regenerate Category Tree         

 Category::regenerateEntireNtree();
Link to comment
Share on other sites

×
×
  • Create New...