Jump to content

How to properly extend prestashop core functionalities


peorthyr

Recommended Posts

Good day all. Sometimes I've found some workarounds to satisfy some kind of needs that explain how to extend some core functionality by editing files like tools.php or frontendController.php. The last one I've found that saved my life, was a function to retrieve the name of a cms page starting from its id and the language id:

public static function getCMSTitle($id_cms,$id_lang){
$cms = new CMS($id_cms, $id_lang);
return $cms->meta_title;
}
<li><a href="{$link->getCMSLink(1)}">{Tools::getCMSTitle(1,$cookie->id_lang)}</a></li>

stackoverflow link

 

 

my question is: 

 

Is it possible to think at these modifications in terms of modules? I mean, is possible to write a module that gives a functionality similar to this, so that expose a new method in all the pages and that can be called in tpl files?

and most important, it NOT alter the core code, so the shop remain upgradable, and the module could be upgraded as needed. 

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

You could make a new class MyTools.php, where you add the function, instead of directly in Tools.php, and then use:

<li><a href="{$link->getCMSLink(1)}">{MyTools::getCMSTitle(1,$cookie->id_lang)}</a></li>

 

 

Just an idea...

 

My $0.02,

pascal.

  • Like 1
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...