justinl Posted January 11, 2012 Share Posted January 11, 2012 Hello, I'm using PS 1.4.4.1 and I'm trying to override the Tools class but my changes in my override class don't seem to be getting picked up. I've overridden many classes before but for some reason I cannot override the Tools class. Is there something I'm doing wrong or is the Tools class not meant to be overridden? Here is my sample code of my override/Tools.php class Tools extends ToolsCore { public static function getHomeMetaTags($id_lang, $page_name) { //do stuff } } Link to comment Share on other sites More sharing options...
Richard S Posted January 11, 2012 Share Posted January 11, 2012 Hello, Do you get any error? Do you put it in the right folder? From what you are deciding it does not override? Maybe the problem is in your code in this method? Link to comment Share on other sites More sharing options...
bellini13 Posted January 11, 2012 Share Posted January 11, 2012 you said ... Here is my sample code of my override/Tools.php It should be located in /override/classes/Tools.php Link to comment Share on other sites More sharing options...
Richard S Posted January 11, 2012 Share Posted January 11, 2012 Ups, missed that part from the first post... It is true. The catalog was wrong for the override. you said ... It should be located in /override/classes/Tools.php Link to comment Share on other sites More sharing options...
justinl Posted January 15, 2012 Author Share Posted January 15, 2012 Woops sorry for my mistake in the path. It is in the override/classes/tools.php folder. I have over a dozen other classes I'm overriding in the same folder as I have my new Tools class. It's a mystery to me as to why it's not working. I've overridden a function and just called die(); in the first line of the function and it still executes php as if nothing is wrong. There is no call to the parent function and when I go into the parent Tools class and modify the function I am trying to override, those changes occur on the front office, so I know the function I'm modifying is the correct one. To confirm, you guys have all overridden the tools class with success? Link to comment Share on other sites More sharing options...
Richard S Posted January 15, 2012 Share Posted January 15, 2012 I am not sure, but try to make the file Tools.php not tools.php, maybe this is a cause of your problems. And yes there usually are not any problems regarding overriding Tools class. Link to comment Share on other sites More sharing options...
justinl Posted January 16, 2012 Author Share Posted January 16, 2012 Thanks for your help guys. I did try both tools.php and Tools.php but neither worked. It's a mystery! If I find out what it was I'll be sure to post back here. Cheers, Justin Link to comment Share on other sites More sharing options...
pberce Posted January 28, 2012 Share Posted January 28, 2012 I'd like to report that I'm having the same problem. I am trying to override the static getPath function in the very same file and it does not work. Prestashop has a _Tools.php file in the override/classes directory which is part of the default install When I installed 2 months ago I renamed override/classes/_Tools.php to override/classes/Tools.php so I could use the firephp logging features included in the file It worked as expected Today I added an override to the override/classes/Tools.php file for the static function getPath and it does not override the getPath function I am using PHP 5.3. Could this be because as of 5.3 the only classes that are allowed to have static abstract classes are interfaces? Link to comment Share on other sites More sharing options...
bellini13 Posted January 29, 2012 Share Posted January 29, 2012 i use php 5.3.4 and overriding Tools works properly. if you want to post your specific override code for getPath, i can test it on my local install to verify Link to comment Share on other sites More sharing options...
pberce Posted January 29, 2012 Share Posted January 29, 2012 I have to explain what I'm doing as I think it will help to understand. I wanted to created a CMS page that would act as a landing page for a CMS category in the breadcrumb. For example: I created an Our Mission CMS page at the top level(under Home). I then created an Our Mission category under Home. I then created another CMS document called Our Team that was a child of the Our Mission category. When viewing the Our Team page the breadcrumb would look like this(link locations for these are in parenthesis): Home(/) > Our Mission(/content/category/3-our-mission) > Our Team(no link, just CMS page name) I modified the getPath function to substitute the link for the CMS page for the category link IF the category name matched the meta-title of a CMS page whose id_cms_category matched the parent_id of the category (this last part allows the code to work on an infinite number of subcategories). Therefore, when all is said and done the breadcrumb would look like this: Home(/) > Our Mission(/content/6-our-mission) > Our Team(no link, just CMS page name) To do this I modified the CMS section of the getPath function in the following manner(see below for the isCMSPage function definition): elseif ($categoryType === 'CMS') { $category = new CMSCategory((int)($id_category), (int)($cookie->id_lang)); if (!Validate::isLoadedObject($category)) die(self::displayError()); if($cms = CMS::isCMSPage($category->name, (int)($cookie->id_lang), $category->id_parent)) $categoryLink = $link->getCMSLink($cms['id_cms'], $cms['link_rewrite']); else $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); } this is a static function I added to my CMS.php override class public static function isCMSPage($name, $id_lang = 1, $id_cms_category) { return Db::getInstance()->getRow(' SELECT c.id_cms, l.link_rewrite FROM `'._DB_PREFIX_.'cms` c JOIN `'._DB_PREFIX_.'cms_lang` l ON (c.id_cms = l.id_cms) WHERE l.meta_title = \''.$name.'\' AND c.id_cms_category = '.(int)$id_cms_category.' AND l.id_lang = '.(int)($id_lang)); } Anyway, in the end my override of the getPath function in Tools.php did not work. I had to change the code of the core files for it to work correctly. I also wanted to reiterate that I used the Tools.php override file created by the Prestashop team, so it must be in the right place and created correctly! Link to comment Share on other sites More sharing options...
bellini13 Posted January 29, 2012 Share Posted January 29, 2012 so to be clear, did your logic fail? or does prestashop fail to invoke your overriden code. There is a difference and I hope you understand the difference. Please clarify. Link to comment Share on other sites More sharing options...
pberce Posted January 30, 2012 Share Posted January 30, 2012 my logic was fine, it worked when I modified the core files. Prestashop failed to invoke my override code in /override/classes/Tools.php Link to comment Share on other sites More sharing options...
bellini13 Posted January 31, 2012 Share Posted January 31, 2012 this works for me. 1) I renamed _Tools.php to Tools.php in the override/classes folder. 2) I copied the entire getPath function from the core Tools class, to my override 3) I added the following line of code as the first statement in the override function Logger::addLog("My get path called"); 4) I went to the front office and selected a category, since the CategoryController calls the getPath function. 5) I went to the back office Tools | Logs section, and I see my entry So this tells me I can override the Tools class, and expect prestashop to invoke it. The issue is something you have not done correctly. Link to comment Share on other sites More sharing options...
Marcello Nuccio Posted November 11, 2012 Share Posted November 11, 2012 I've had the same problem, and I've solved it by deleting the file cache/class_index.php Hope it helps others. 3 Link to comment Share on other sites More sharing options...
sinoland Posted September 30, 2013 Share Posted September 30, 2013 I've had the same problem, and I've solved it by deleting the file cache/class_index.php Hope it helps others. Hi Marcello, You're right. My Tools.php override works now. Thank you. 1 Link to comment Share on other sites More sharing options...
aualtopoll Posted October 11, 2013 Share Posted October 11, 2013 I've had the same problem, and I've solved it by deleting the file cache/class_index.php Hope it helps others. That solved it. Plain and simple. Thanks man. 1 Link to comment Share on other sites More sharing options...
bellini13 Posted October 11, 2013 Share Posted October 11, 2013 some versions of Prestashop do not properly regenerate the class index. It was a bug fix in the more recent versions. If you create an override, try to delete the file. If that does not work, then you need to manually update the class index Link to comment Share on other sites More sharing options...
mkaare Posted April 7, 2014 Share Posted April 7, 2014 Deleting cache/class_index.php works fine if i don't use debug mode. But if in config/defines.inc.php is enabled debug profiling: define('_PS_DEBUG_PROFILING_', true); Then i can't override Tools class. Tools class is already included in config/config.inc.php file and my override/classes/Tools.php file is never included: if (_PS_DEBUG_PROFILING_) { include_once(_PS_TOOL_DIR_.'profiling/Controller.php'); include_once(_PS_TOOL_DIR_.'profiling/ObjectModel.php'); include_once(_PS_TOOL_DIR_.'profiling/Hook.php'); include_once(_PS_TOOL_DIR_.'profiling/Db.php'); include_once(_PS_TOOL_DIR_.'profiling/Tools.php'); } Prestashop version: 1.5.6.2 1 Link to comment Share on other sites More sharing options...
trevorgilligan Posted April 1, 2015 Share Posted April 1, 2015 I've had the same problem, and I've solved it by deleting the file cache/class_index.php Hope it helps others. i helped me so thank you. i spent 5 hours today with a cannot find tools core class. getting frustrated at using prestashop if its not simple to use its no help. im trying to use multistore. yet the themes come up all over the place on different stores. v frustrating . still thank you for your help. trev Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now