Jump to content

[Résolu] Intégration Rich Snippets > Breadcrumb 1.5.3


Recommended Posts

Bonjour,

 

Je suis sur une version 1.5.3 de prestashop. J'aurais aimé faire l'intégration de rich snippets pour mon fil d'ariane. J'ai suivi les recommandations faites ici mais la modification du fichier Tools est toujours valable pour la version 1.5 ? J'ai pas essayé...

 

Le tuto donne la marche à suivre pour les versions antérieures, pas de MAJ depuis.

 

Merci d'avance :)

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

Voila la modification à faire du fichier tools.php

 

fonction getPath ligne 858

public static function getPath($id_category, $path = '', $link_on_the_item = false, $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);
 }
}

 

Fichier breadcrumb.tpl :

 

<!-- Breadcrumb -->
{if isset($smarty.capture.path)}{assign var='path' value=$smarty.capture.path}{/if}
<div class="breadcrumb" style="display:inline">
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="{$base_dir}" title="{l s='return to Home'}" itemprop="url"><span itemprop="title">{l s='Home'}</a></div>
{if isset($path) AND $path}
 <span class="navigation-pipe" {if isset($category) && isset($category->id_category) && $category->id_category == 1}style="display:none;"{/if}></span>
 {if !$path|strpos:'span'}
  <span class="navigation_page">{$path}</span>
 {else}
  {$path}
 {/if}
{/if}
</div>
<!-- /Breadcrumb -->

 

Voilà réussi finalement ^^

  • Like 3
Link to comment
Share on other sites

Voila la modification à faire du fichier tools.php

 

fonction getPath ligne 858

public static function getPath($id_category, $path = '', $link_on_the_item = false, $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);
 }
}

 

Fichier breadcrumb.tpl :

 

<!-- Breadcrumb -->
{if isset($smarty.capture.path)}{assign var='path' value=$smarty.capture.path}{/if}
<div class="breadcrumb" style="display:inline">
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="{$base_dir}" title="{l s='return to Home'}" itemprop="url"><span itemprop="title">{l s='Home'}</a></div>
{if isset($path) AND $path}
 <span class="navigation-pipe" {if isset($category) && isset($category->id_category) && $category->id_category == 1}style="display:none;"{/if}></span>
 {if !$path|strpos:'span'}
  <span class="navigation_page">{$path}</span>
 {else}
  {$path}
 {/if}
{/if}
</div>
<!-- /Breadcrumb -->

 

Voilà réussi finalement ^^

 

 

Romain,

 

Do you happen to know how & where in these scripts to modify so that we get as active hyperlink the lowest level breadcrumb [ ex. Page Breadcrumb or SubCategory Beadcrumb ] ?

 

It sems to be very important as of 2013, in AdWords Dynamic Ads , AdWords Quality score and Relevance score.

 

thanks,

 

r

 

PS. I succeded to make Category link "active" in the breadcrumb. Works for Category and Subcategory when it is current page.

 

I still have to discover for Product page.

 

/classes/Tools.php

 

look fo getPath

 

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

Edited by radus (see edit history)
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...