Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 316 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prestashop - override function in existing prestashop module

#1
I would like to change existing prestashop module without copying it and creating new one. I know that it is possible to override .tpl files in prestashop, but is it possible to do same thing with php classes? For instance I would like to change blockcart so that it can be hooked on top. Since original version doesnt have that hook I need to change install() function! I can`t change original source (it would be bad idea isn't it...) file I need to override install() function by inheriting blockcart module. Is it possible to do so and where I can find example?
Reply

#2
In Prestashop 1.4 you can override core classes and module templates
Today this is not possible to override a module php file but we are working on it.
Reply

#3
I use my own override to the FrontController class to allow the display of module output at arbitrary points in tpl files - this means that the module doesn't need to support a particular hook. It is implemented via a smarty plugin, so you can for example use:

{plugin module='blockcart' hook='rightColumn'}

The above will force the module to output what it would display if hooked to the right column where the above is tag inserted (which can be anywhere in any tpl file). You can "unhook" the module from the right column so that it only displays where you want it to using this technique. I have used it on a production site with great success.

There's a series of articles describing how it works (with the required code) available at:

[Prestashop 1.4 Plugins][1]


[1]:

[To see links please register here]

Reply

#4
Since version 1.6.0.11 of PrestaShop, there is a new feature that allows developers to override a module’s instance classes.

**Override a module’s instance class by extending it**
To override a module’s instance class, you have to extend it, giving the extended class the same name and adding Override suffix:

<?php
if (!defined('_PS_VERSION_'))
exit;
class BlockUserInfoOverride extends BlockUserInfo
{
public function hookDisplayNav($params)
{
return '<div class="header_user_info"><a>Test</a></div>';
// return $this->display(__FILE__, 'nav.tpl');
}
}

Source:

[To see links please register here]

Reply

#5
in override\modules\blockcart\blockcart.php (create it if it does not exist yet)

<?php
class BlockCartOverride extends BlockCart
{
public function hookDisplayTop($params)
{
return parent::hookTop($params);
}
}
?>


like this you can override any module to be hookable on any default or custom hook.
don't forget to delete cache/class_index.php for the override to work :)
Reply

#6
Keep in mind that in 1.7.x era - nowadays - you can override module main classes but not controllers. To be able to override controllers you have to override the core classes (to detect any possible overrides) and then do whatever you like. Alternatively, you have to get the original files as backup and put the modified in the same place on install and the reverse procedure on uninstall.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through