Prestashop

Prestashop: Override Tools Class

Posted on

Recently, I tried overriding the meta tags on my homepage in one of my prestashop sites.
Here is what I did, made a new class in the folder overrides/classes/Tools.php and created
class Tools extends ToolsCore

I tried overriding the
public static function getHomeMetaTags
in my overridden class.

But something seemed to be wrong, and getHomeMetaTags function from the core parent class was being called instead of the child class’s getHomeMetaTags function.
After going through the code for a few hours, I found that the getHomeMetaTags was being called as self::getHomeMetaTags($id_lang, $page_name); in the function getMetaTags() in the parent.

So the problem was self::getHomeMetaTags($id_lang, $page_name); // PHP binds this to ToolsCore::getHomeMetaTags() right away
This would call the getHomeMetaTags function of the core class

So in order to override the getHomeMetaTags() function I also had to override the getMetaTags() function so that the self::getHomeMetaTags($id_lang, $page_name) function call in the child class would call the function of the same child Class.

To sum up, In order to override the static method getHomeMetaTags in child Tools class, you will also have to override the getMetaTags method as well in the child class.

Thank you for reading.
Hope this was helpful to you.
Cheers!!