Jump to content
thirty bees forum
  • 0

Remove part of breadcrumb on product page


Question

5 answers to this question

Recommended Posts

  • 0
Posted

You need to override the function assignCategory() in ProductController.php

Change 

$path = Tools::getPath($this->category->id, $this->product->name, true);

to 

$path = Tools::getPath($this->category->id, '', false);

 

  • Like 1
  • Thanks 1
  • 0
Posted
On 10/17/2019 at 7:33 AM, wakabayashi said:

You need to override the function assignCategory() in ProductController.php

Change 


$path = Tools::getPath($this->category->id, $this->product->name, true);

to 


$path = Tools::getPath($this->category->id, '', false);

 

While this technique worked in PS 1.6.x for me, it does not work in my configuration of TB 1.3.0 and Panda 1.5.5.

Using the Panda 1.5.5 Theme - this caused a different behavior; the breadcrumb had the correct text, but the last category "breadcrumb" displayed contained the url to the product page instead of the category. After digging through Tools.php and productController.php, it dawned on me that the last breadcrumb was being modified somewhere else... enter /themes/panda/breadcrumb.tpl

I am including the entire code section so you can see what I commented out. I'm currently pressed for time in this migration effort, so eventually I will come back and clean this up a bit more (beginning line is ~28):

{if !empty($path)}
	{* Extract bradcrumb links from anchors *}
	{$matchCount = preg_match_all('/<a.+?href="(.+?)"[^>]*>([^<]*)<\/a>/', $path, $matches)}
	{$breadcrumbs = []}
	{for $i=0; $i<$matchCount; $i++}
		{$breadcrumbs[] = ['url' => $matches[1][$i], 'title' => $matches[2][$i]]}
	{/for}

	{* Extract the last breadcrumb which is not link, it's plain text or text inside span *}
	{* $match = preg_match("/>([^<]+)(?:(?:<\/\w+>)*\s*)?$/", $path, $matches) *}
	{* if !empty($matches[1]) *}
		{* $breadcrumbs[] = ['url' => '', 'title' => $matches[1]] *}
	{* elseif !$match && !$matchCount *}
		{* $breadcrumbs[] = ['url' => '', 'title' => $path] *}
	{* /if *}
{/if}

By removing the "Extract the last breadcrumb..." code block, the entire product name and the associated link that was getting added to the last item in the breadcrumb is now removed with no other modifications necessary in the code or the overrides.

Hope this helps somebody else out!

  • 0
Posted
On 2/16/2022 at 11:31 AM, DarkHorse said:

While this technique worked in PS 1.6.x for me, it does not work in my configuration of TB 1.3.0 and Panda 1.5.5.

Using the Panda 1.5.5 Theme - this caused a different behavior; the breadcrumb had the correct text, but the last category "breadcrumb" displayed contained the url to the product page instead of the category. After digging through Tools.php and productController.php, it dawned on me that the last breadcrumb was being modified somewhere else... enter /themes/panda/breadcrumb.tpl

I am including the entire code section so you can see what I commented out. I'm currently pressed for time in this migration effort, so eventually I will come back and clean this up a bit more (beginning line is ~28):

{if !empty($path)}
	{* Extract bradcrumb links from anchors *}
	{$matchCount = preg_match_all('/<a.+?href="(.+?)"[^>]*>([^<]*)<\/a>/', $path, $matches)}
	{$breadcrumbs = []}
	{for $i=0; $i<$matchCount; $i++}
		{$breadcrumbs[] = ['url' => $matches[1][$i], 'title' => $matches[2][$i]]}
	{/for}

	{* Extract the last breadcrumb which is not link, it's plain text or text inside span *}
	{* $match = preg_match("/>([^<]+)(?:(?:<\/\w+>)*\s*)?$/", $path, $matches) *}
	{* if !empty($matches[1]) *}
		{* $breadcrumbs[] = ['url' => '', 'title' => $matches[1]] *}
	{* elseif !$match && !$matchCount *}
		{* $breadcrumbs[] = ['url' => '', 'title' => $path] *}
	{* /if *}
{/if}

By removing the "Extract the last breadcrumb..." code block, the entire product name and the associated link that was getting added to the last item in the breadcrumb is now removed with no other modifications necessary in the code or the overrides.

Hope this helps somebody else out!

Just found this post. I'm curious, were you able to get rid of the last "after" navigation arrow as well? I followed your directive and it did remove the product correctly, but it left the last arrow.  Thanks.

  • Like 1
  • 0
Posted (edited)
On 8/14/2022 at 10:39 PM, x97wehner said:

Just found this post. I'm curious, were you able to get rid of the last "after" navigation arrow as well? I followed your directive and it did remove the product correctly, but it left the last arrow.  Thanks.

^^ Just use wakabayashi's code above ^^

For those who might run across this after TB 1.3.0

Edited by DarkHorse
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...