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?
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
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.
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 :)
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: http://build.prestashop.com/howtos/module/how-to-override-modules/
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.
Related
I am making a module, that suposed to use templates from my custom theme.
The problem is that I don't understand the function Module::display(), it gets two arguments "file" and "template", what is the file? What is it for?
If I do this:
public function hookDisplayHome{
return $this->display(__FILE__, '../../templates/my_custom_theme/mb_templates/aboutus.tpl');
}
It displays error "Not found template file" in module "my_module". Of course if I change the template path to one of the templates of my module, then it works. But I need to access theme's template, not my module's.
With this I have also another additional question. Is there any documentation on Prestashop's functions? I really tried to analyse the function $this -> display() but couldn't find any place where is described what are the arguments of this function etc. There is Prestashop documentation https://devdocs.prestashop.com but it is very general, and has no description of the functions.
I've checked the class Module.php, the function has no comments :(
What is the official way when you want to check what the function does, returns, and what parameters accepts? It has to be somewhere, right?
So for those who also struggle with this problem, based on this answer https://stackoverflow.com/a/53576139/2796533
The easiest solution seems to be using module's template in $this -> display() and then in that template include the theme's template:
{include file='../../../themes/my_custom_theme/mb_templates/aboutus.tpl'}
I need a hook that I can't find in the documentation, but logically it should exist.
In my module, I need to add some html in category page (or search results page) after the tile with the products but before pagination.
Which hook is best to use?
There is no default hook for your goal, but you can create your own one and use it within your module. The inconvenience is that you will be able to use it only in modified themes or you will need to add it manually to all new ones. To create the desirable hook you need to put
{hook h='displayYourHook' info=$someData}
in the top of your_theme/templates/catalog/_partials/products-top.tpl
and then just use it like a default hook within your module
public function hookDisplayYourHook($params)
{
// $params can be some information. ID of category for example
do all necessary stuff here
}
and also do not forget to register your hook during the module installation
public function install()
{
....
&& $this->registerHook('addproduct')
....
}
Also, I presume that you use prestashop 1.7.* if not - some code can be different
I am new in Yii. And some things in this framework i am understand well. But i am can't understand how work Yii::app() and where i can find Yii::app()->user->checkAccess method?
Should you are explain me it. Thanks!
Yii::app()->user is the user component, which is defined in your config file (usually /protected/config/main.php). In the components array you will find a 'user' component. The default class for this is CWebUser, so probably 'checkAccess' is defined in CWebUser (did not check this though).
You can write your own class extending CWebUser if you want to override this property (it's not a method).
See your /protected/config/main.php file, and then you may find authManager section in components. In my case, I set the class of authManager to CDbAuthManager. In that class, checkAccess method is defined.
I am writing a module, I know how to build a global module, but I would like to do the following:
Have global properties (already covered)
Have the same properties in a tab in the products interface in the admin where the user can override the global properties (still to do)
Now my question:
How do I add an additional tab to the products interface in the prestashop admin?
I guess I can easily call these in my module templates and check if global is overridden?
Thanks for the feedback,
Eric
PS. Using prestashop 1.5.8, will worry later to extend to 1.6
To add an additional tab to product edit page, you can use hookDisplayAdminProductsExtra.
First, you will have to register this hook inside install() method:
public function install() {
...
$this->registerHook('displayAdminProductsExtra')...
...
}
after that you define this:
public function hookDisplayAdminProductsExtra($params) {
...
return $this->display(__FILE__, 'views/admin/yourtemplatefile.tpl');
}
File yourtemplatefile.tpl defines the contents of your extra tab. Extra variables used in this file can be assigned inside hookDisplayAdminProductsExtra function
Here you can find additional information about creating a module:
http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module
And here you can find information about hooks:
http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5
I'm working on styling the breadcrumb module.
Am I able to remove this class: RadSiteMap? I'd like to add my own styles to it.
I'm not sure you can remove that particular class, because I believe it is automatically generated by the control as it renders (you'd have to inherit from it and override this behavior, and even then I'm not sure it's possible).
your best bet is to use CSS to override that class properties. What you can do however, is use an external template (http://www.sitefinity.com/blogs/joshmorales/posts/josh-morales-blog/2011/05/10/mapping_external_templates_for_sitefinity_4_widgets) which will allow you to change the default CSS styles applied to the control (for breadcrum it has a wrapper class of "sfBreadcrumbWrp" and label class of "sfBreadcrumbLabel"
These are defined right in the template and can be changed as needed.
I hope this is helpful!