Jump to content

Breadcrumb - Active Link For Last Item


radus

Recommended Posts

Hi,

 

I wanted to have last item as hyperink in template breadcrumb

 

I had success for making it on Category and Subcategory if they were last pages, but not for Product page, which is like default [ no hyperlink ].

 

Below is the code; getPath modification to make page name breadcrumb as active hyperlink using page friendly url, is what I look for.

 

Thanks in advance.

 

/theme/theme/

 

<!-- Breadcrumb -->

{if isset($smarty.capture.path)}{assign var='path' value=$smarty.capture.path}{/if}

<div class="breadcrumb">

<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" href="{$base_dir}" title="{$shop_name|escape:'htmlall':'UTF-8'}"><img src="{$img_dir}icon/home.gif" height="18" width="18" title="{$shop_name|escape:'htmlall':'UTF-8'}" alt="{$shop_name|escape:'htmlall':'UTF-8'}" /></a></div>

{if isset($path) AND $path}

<span class="navigation-pipe">{$navigationPipe|escape:html:'UTF-8'}</span>

{if !$path|strpos:'span'}

<span class="navigation_page">{$path}</span>

{else}

{$path}

{/if}

{/if}

</div>

<!-- /Breadcrumb -->

 

 

 

/classes/Tools.php look for getPath

 

* Get the user's journey

*

* @param integer $id_category Category ID

* @param string $path Path end

* @param boolean $linkOntheLastItem Put or not a link on the current category

* @param string [optionnal] $categoryType defined what type of categories is used (products or cms)

*/

public static function getPath($id_category, $path = '', $link_on_the_item = true, $category_type = 'products', Context $context = null)

{

if (!$context)

$context = Context::getContext();

 

$id_category = (int)$id_category;

if ($id_category == 1)

return '<span class="navigation_end">'.$path.'</span>';

 

$pipe = Configuration::get('PS_NAVIGATION_PIPE');

if (empty($pipe))

$pipe = '>';

 

$full_path = '';

if ($category_type === 'products')

{

$interval = Category::getInterval($id_category);

$id_root_category = $context->shop->getCategory();

$interval_root = Category::getInterval($id_root_category);

if ($interval)

{

$sql = 'SELECT c.id_category, cl.name, cl.link_rewrite

FROM '._DB_PREFIX_.'category c

LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category'.Shop::addSqlRestrictionOnLang('cl').')

WHERE c.nleft <= '.$interval['nleft'].'

AND c.nright >= '.$interval['nright'].'

AND c.nleft >= '.$interval_root['nleft'].'

AND c.nright <= '.$interval_root['nright'].'

AND cl.id_lang = '.(int)$context->language->id.'

AND c.active = 1

AND c.level_depth > '.(int)$interval_root['level_depth'].'

ORDER BY c.level_depth ASC';

$categories = Db::getInstance()->executeS($sql);

 

$n = 1;

$n_categories = count($categories);

foreach ($categories as $category)

{

$full_path .=

(($n < $n_categories || $link_on_the_item) ? '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="'.Tools::safeOutput($context->link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'" itemprop="url"><span itemprop="title">' : '').

htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').

(($n < $n_categories || $link_on_the_item) ? '</span></a></div>' : '').

(($n++ != $n_categories || !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : '');

}

 

return $full_path.$path;

}

}

else if ($category_type === 'CMS')

{

$category = new CMSCategory($id_category, $context->language->id);

if (!Validate::isLoadedObject($category))

die(Tools::displayError());

$category_link = $context->link->getCMSCategoryLink($category);

 

if ($path != $category->name)

$full_path .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="'.Tools::safeOutput($category_link).'" itemprop="url"><span itemprop="title">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</span></a></div><span class="navigation-pipe">'.$pipe.'</span>'.$path;

else

$full_path = ($link_on_the_item ? '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="'.Tools::safeOutput($category_link).'" itemprop="url"><span itemprop="title">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($link_on_the_item ? '</span></a></div>' : '');

 

return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, $category_type);

}

}

 

/**

* @param string [optionnal] $type_cat defined what type of categories is used (products or cms)

*/

public static function getFullPath($id_category, $end, $type_cat = 'products', Context $context = null)

{

if (!$context)

$context = Context::getContext();

 

$id_category = (int)$id_category;

$pipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>');

 

$default_category = 1;

if ($type_cat === 'products')

{

$default_category = $context->shop->getCategory();

$category = new Category($id_category, $context->language->id);

}

else if ($type_cat === 'CMS')

$category = new CMSCategory($id_category, $context->language->id);

 

if (!Validate::isLoadedObject($category))

$id_category = $default_category;

if ($id_category == $default_category)

return htmlentities($end, ENT_NOQUOTES, 'UTF-8');

 

return Tools::getPath($id_category, $category->name, true, $type_cat).'<span class="navigation-pipe">'.$pipe.'</span> <span class="navigation_product">'.htmlentities($end, ENT_NOQUOTES, 'UTF-8').'</span>';

}

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

  • 1 month later...

Well, this is not a very active forum and prestashop lacks a serious documentation for developers. For your question, I somehow modified breadcrumbs for my project. You have to certain steps in order to add lastItem class to your breadcrumn

 

1. Override Tools.php to override/classes/Tools.php

2. Name your class "class Tools extends ToolsCore{ }"

3. Copy getPath function to your newly created Tools.php

4. Delete file from cache/class_index.php

 

Now that you have overrided that function, your can do whatever you want, specific to your question you can add lastClass to your item like this.

On line 61 or 62

 

Before

return $full_path.$path

 

After



if ($path) {
                   $item = $full_path . "<li class="lastItem"><a href="javascript:;">" . $path . "</a></li>";
               } else {
                   $item = "<li class="lastItem"><a href="javascript:;">" . $full_path . "</a></li>" . $path;
               }
               return $item;

 

Hope it helps.

 

Regards

post-555269-0-72941500-1367491760_thumb.png

Edited by murtaza.dev (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 4 months later...
  • 1 year later...

Hi,
 
I've managed to modify last element for categories and products thanks to murtaza's help, but when I go through my account, it does not work.
 
Code is:
 
<div class="breadcrumb">
   <a title="return to Home" href="http://www.dail-software.com/">Home</a>
       <span class="navigation-pipe"></span>
            <a href="https://www.dail-software.com/en/my-account">My account</a>
             <span class="navigation-pipe"> </span>
        Order history
</div>

 

and it should be:

 

<div class="breadcrumb">
    <a title="return to Home" href="http://www.dail-software.com/">Home</a>
    <span class="navigation-pipe"></span>
    <span class="navigation_path">
        <a href="https://www.dail-software.com/en/my-account">My account</a>
        <span class="navigation-pipe"> </span>
        Order history
    </span>
</div>

 

Can anybody help me?

 

Thanks

Link to comment
Share on other sites

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...