Jump to content

wanting to change a function in tools.php how do i use overide


devilsown

Recommended Posts

I tired removing the _ in tools.php in the overides folder and copying this in but it did not work.

Anyone have any ideas how i can set it up so i don't loose my custmation when newer updates come out.?

 

 

/**
* 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 = '', $linkOntheLastItem = false, $categoryType = 'products')
{
 global $link, $cookie;
 if ($id_category == 1)
  return '<li>'.$path.'</li>';
 $pipe = Configuration::get('PS_NAVIGATION_PIPE');
 if (empty($pipe))
  $pipe = '>';
 $fullPath = '';
 if ($categoryType === 'products')
 {
  $category = Db::getInstance()->getRow('
  SELECT id_category, level_depth, nleft, nright
  FROM '._DB_PREFIX_.'category
  WHERE id_category = '.(int)$id_category);
  if (isset($category['id_category']))
  {
   $categories = Db::getInstance()->ExecuteS('
   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)
   WHERE c.nleft <= '.(int)$category['nleft'].' AND c.nright >= '.(int)$category['nright'].' AND cl.id_lang = '.(int)($cookie->id_lang).' AND c.id_category != 1
   ORDER BY c.level_depth ASC
   LIMIT '.(int)$category['level_depth']);
   $n = 1;
   $nCategories = (int)sizeof($categories);
   foreach ($categories AS $category)
   {
 $fullPath .=
 (($n < $nCategories OR $linkOntheLastItem) ? '<a href="'.self::safeOutput($link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : '').
 htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').
 (($n < $nCategories OR $linkOntheLastItem) ? '</a>' : '').
 (($n++ != $nCategories OR !empty($path)) ? ' <li>' : '');
   }
   return $fullPath.$path;
  }
 }
 elseif ($categoryType === 'CMS')
 {
  $category = new CMSCategory((int)($id_category), (int)($cookie->id_lang));
  if (!Validate::isLoadedObject($category))
   die(self::displayError());
  $categoryLink = $link->getCMSCategoryLink($category);
  if ($path != $category->name)
   $fullPath .= '<a href="'.self::safeOutput($categoryLink).'">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</a><span class="navigation-pipe">'.$pipe.'</span>'.$path;
  else
   $fullPath = ($linkOntheLastItem ? '<a href="'.self::safeOutput($categoryLink).'">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($linkOntheLastItem ? '</a>' : '');
  return self::getPath((int)($category->id_parent), $fullPath, $linkOntheLastItem, $categoryType);
 }
}

Link to comment
Share on other sites

Leave _Tools.php like it was and create new Tools.php with this code

 

<?php
class Tools extends ToolsCore
{
/**
* 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 = '', $linkOntheLastItem = false, $categoryType = 'products')
{
  global $link, $cookie;
  if ($id_category == 1)
return '<li>'.$path.'</li>';
  $pipe = Configuration::get('PS_NAVIGATION_PIPE');
  if (empty($pipe))
$pipe = '>';
  $fullPath = '';
  if ($categoryType === 'products')
  {
$category = Db::getInstance()->getRow('
SELECT id_category, level_depth, nleft, nright
FROM '._DB_PREFIX_.'category
WHERE id_category = '.(int)$id_category);
if (isset($category['id_category']))
{
 $categories = Db::getInstance()->ExecuteS('
 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)
 WHERE c.nleft <= '.(int)$category['nleft'].' AND c.nright >= '.(int)$category['nright'].' AND cl.id_lang = '.(int)($cookie->id_lang).' AND c.id_category != 1
 ORDER BY c.level_depth ASC
 LIMIT '.(int)$category['level_depth']);
 $n = 1;
 $nCategories = (int)sizeof($categories);
 foreach ($categories AS $category)
 {
$fullPath .=
(($n < $nCategories OR $linkOntheLastItem) ? '<a href="'.self::safeOutput($link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : '').
htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').
(($n < $nCategories OR $linkOntheLastItem) ? '</a>' : '').
(($n++ != $nCategories OR !empty($path)) ? ' <li>' : '');
 }
 return $fullPath.$path;
}
  }
  elseif ($categoryType === 'CMS')
  {
$category = new CMSCategory((int)($id_category), (int)($cookie->id_lang));
if (!Validate::isLoadedObject($category))
 die(self::displayError());
$categoryLink = $link->getCMSCategoryLink($category);
if ($path != $category->name)
 $fullPath .= '<a href="'.self::safeOutput($categoryLink).'">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</a><span class="navigation-pipe">'.$pipe.'</span>'.$path;
else
 $fullPath = ($linkOntheLastItem ? '<a href="'.self::safeOutput($categoryLink).'">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($linkOntheLastItem ? '</a>' : '');
return self::getPath((int)($category->id_parent), $fullPath, $linkOntheLastItem, $categoryType);
  }
}
}

 

So what I think that you missed is

class Tools extends ToolsCore
{
...
}

 

Here are some link that maybe could explain more

http://www.nethercot...rriding-classes

http://doc.prestasho...roller+Override

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