Show module Content in theme Development [Prestashop] - 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"}

Related

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

Creating module on prestashop

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)

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

yii efullcalendar widget and external events drag and drop not working

Hi I am trying to use drag and drop external events for fullcalendar and get working with the yii extension full calender - which seems to be just a wrapper.
The part that is not working (no errors just does not work) is dragging the external event onto the calendar and it staying there. It drags over but it just returns home.
Reading the fullcalendar docs - it looks like I need to provide a callback function to 'drop' attribute. I've been using the external-event example which is part of full calendar. I did discover the example was using the object name '#calendar' and that yii is creating name '#yw0' but it still didn't work after I updated.
I cannot find a way to get it work. I tried a simple alert which sort of works, it is called on page load - not after a drag operation.
So I declared a variable with the function in View
//$dropcallback=new CJavaScriptExpression("alert('hi')");
$dropcallback=new CJavaScriptExpression(
"function(date, allDay) {
var originalEventObject = $(this).data('eventObject');
var copiedEventObject = $.extend({}, originalEventObject);
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
$('#yw0').fullCalendar('renderEvent', copiedEventObject, true);
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the Draggable Events list
$(this).remove();
}
}
");
Then I create the widgit like this
$this->widget('ext.EFullCalendar.EFullCalendar', array(
'themeCssFile'=>'cupertino/jquery-ui.min.css',
'options'=>array(
'header'=>array(
'left'=>'prev,next',
'center'=>'title',
'right'=>'today'
),
'editable'=>true,
'dropable'=>true,
'drop'=>$dropcallback,
'events'=>Game::model()->gameCalendarData(),
)));
My yii experiance is little and same with JS - so any help appreciated in how to get this working.
I understand that in JS you need to provide a callback to allow the drag op to succeed. But what sort of call back do I need when it is wrapped in a yii widgit? I tried a PHP callback and again it is only called on page load.
The result I wish is that I can build the external events list from the DB - allow users to drag them onto the calendar - and save them in the DB.
I did manage to get data from DB displayed in the calendar.
Thanks
Droppable is spelt with two p's. So
'dropable'=>true,
Should be
'droppable'=>true,

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
}