Creating module on prestashop - module

i need to create a module on prestashop on product page , im new in prestashop idk how to do that .
This module should be on bottom of page ,it contains product technical description
Can someone tell me how to do that
Ps : i know nothing about prestashop Hooks ....
Thanks in advance!

There is one hook that may fit you.
displayProductFooter
First you have to add the hook registration in your module install function
public function install()
{
...
$this->registerHook('displayProductFooter');
}
Then create a function to display the content in the hook
Save the content you want to display and use the return to send a string with all the HTML you want to print in the product footer.
In the params you will also find some useful variables like the product ID.
public function hookDisplayProductFooter($params)
{
// Your content here
return $output;
}
The same procedure should work with any other hook (as long as it's a display hook)

Related

In Opencart 3 under PHP 8 how do I call module to show in another page

I have seen on this site the post re calling a module on needed page. I have tried to use this code to solve a problem. This code does not appear to work for me.
What I have is a module that places a label over each product depending on its status. It works well on products throughout site. However I have a module which calls all products on to one page. I want the label to appear on the products on this all products page.
Banner on product
The code I used in catalog/controller for the all product extension from previous post here was (382 is the label module number):
$this->load->model('382');
$my_variable = $this->model_setting_module->getModule('382');
$data['any_variable'] = $my_variable['any_variable'];
On Template page:
{{ any_variable }}
How can I get the module to be apply the label to the custom all products page?
As always help appreciated
Create new module with name: "my_module" and you can call it in your "another_module" controller file:
$data['my_module'] = $this->load->controller('extension/module/my_module');
and in corresponding "another_module" template file you can retrieve it:
{{ my_module }}

How can I change the module position from code in Prestashop 1.7?

I learn actually Module Programming in Prestashop 1.7.... hard work but really good.
So, when I install my first module,
public function install()
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if ( !parent::install() or
!$this->registerHook('displayTop') or
!$this->registerHook('header') or
!$this->registerHook('backOfficeHeader') )
return false;
return true;
}
the position will automatically set at the end of the hook displayTop.
Now, what must I do to set it on the first place ?
I have read it will works with the function "updatePosition", unfortunately I find only tips of 2012 and 2-3 years earlyier.
The developer docs have a hint here,
https://devdocs.prestashop.com/1.7/development/components/position-updater/
but I don't understand how to implant it into your module.
Does anyone have the time to explain me how the desired order is laid out by the code?
And does this happen in the install method or from where?
Go to your admin panel, in "**Design**" then "**Position**".
Look for '**displayTop**' in the "**Search for hook**" search bar at your top-right.
Then drag and drop your module which is in the last row and place it in the first row.
Change module's position in the hook list

Prestashop 1.6 - How to add a dynamic class to the body element

In a Prestashop 1.6 site I need add a dynamic class to the body element (just in frontend).
The class should be 'group-[group-name-id]' where group-name-id is the group name id of the visitor.
Default Groups in Presashop are:
'1'--'Visitor'
'2'--'Guest'
'3'--'Costumer'
Is there a way to do this?
I found this, but it seems outdated, since it is for PS 1.4: https://www.prestashop.com/forums/topic/179593-adding-category-class-id-to-product-page-body/
UPDATE:
I almost get it thanks to #TheDrot answer (just below).
The only problem is this: [0]. I get this error: "Parse error: syntax error, unexpected '[', expecting ')' in /home/temporal-4/www/override/classes/controller/FrontController.php on line 36".
If I remove '[0]' it works but then in the class I get "group-array". I need to print all the values of the array like class="group-1 group-2 group-3".
You need to override FrontControllerCore class so create a file FrontController.php in folder 'override/classes/controller/' and put in this code
class FrontController extends FrontControllerCore {
public function init()
{
parent::init();
$this->context->smarty->assign('group_id', $this->context->customer->getGroups()[0]; // user can exist in multiple groups, so for this example im just grabbing first group id
}
}
Then open header.tpl file in 'themes/your_theme/' and add code to body class
group-{$group_id}
If in body class you only see group-, be sure to delete class_index.php from cache folder and reload page.
For PS1.7 no need to override anything, perhaps it works for PS1.6
Add $groupid = "group-1" or "group-2", ect. to smarty params by using assign() function in your controller and in your template add on top
{$page["body_classes"][$groupid] = 'true'}
Let us know about this tricks

Show module Content in theme Development [Prestashop]

I am trying to create a theme using Prestashop 1.6 and the Default theme as reference.
Whenever i try
{HOOK_TOP}
in my header.tpl , it display the search,cart modules.
But in my case i just want the search module to be displayed.How can i display only the search block and the signIn,create account i want them to be displayed in another place.
Also can i get any advice or tutorials from where i can learn the theming the right way.I guess i am doing stuff the wrong way.
You can create new hooks for each module you want to display elsewhere.
By default, the blocks you don't want are hooked to TOP.
You need to un-hook those from TOP.
Create new one :
- sql :
INSERT INTO ps_hook (name,title,description,position,live_edit) VALUES ('yourNewHook','title of your new hook', 'description of your new hook', '1', '1');
INSERT INTO ps_hook_alias (alias, name) VALUES ('the alias of your new hook','yourNewHook');
controller :
public function hookYourNewHook ($param) {
if (!$this->_prepareHook($param))
return;
return $this->display(FILE, 'templateofyournewhook.tpl');}
Modify or add a register hook in public function install() : $this->registerHook(' alias of your new hook')
Now you can call your hook in a tpl with {hook h="yourNewHook"}

In prestashop how to write code for disable a module function only for specified categories

I need to disable a module only for a particular category.How do i need to write code for making the module to diable for those categories.
like this (if you want to disable your module for id category 4) :
$id_category = (int)Tools::getValue('id_category');
if($id_category !==4){
//some code
}