Reputation: 219
I need to move my hook right between the product description and the add button to the cart, in the area I marked in the photo
So far I can only put it before and after the buttons of social networks using the admin, but I need to put my module before the button.
This is how I create my hook:
public function install()
{
if (!parent::install() || !$this->registerHook('displayProductAdditionalInfo'))
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall() || !$this->unregisterHook('displayProductAdditionalInfo'))
return false;
return true;
}
public function hookDisplayProductAdditionalInfo($params)
{
return $this->runnable();
}
And this is my file that contains the iframe that I want to show
{block name='product_description_short' prepend}
<style type='text/css'>
.products { border: none; width: 100%; height: {$height}px; }
</style>
<iframe class='products' src='{$iframe}{$token}'></iframe>
{/block}
How can I do to move the hook to where I need to, without having to touch the source code of the theme?
Upvotes: 1
Views: 1622
Reputation: 5067
This is exactly what the concept of widget aims at. Widgets is an advanced feature introduced in PS 1.7 that extends the hooks feature.
From the documentation:
With widgets, module developers can display content everywhere the module is asked to do so. When a module implements widgets in its code, it allows:
1 a theme to call the module directly with {widget name="module_name"}
2 the core to fallback on it if a registered hook is called but its method hook() does not exist.
By following the same link you can make a module widgets compliant and then call the widget in templates/catalog/product.tpl
in the place you want.
In classic theme for 1.7.5.0, you can call the widget in line 98 just before <div class="product-actions">
.
Hope it helped.
Edit:
Let's assume your module name is 'my_module' and your custom hook name is 'myCustomHook', Here is how the module class should look like:
class MyModule extends Module implements WidgetInterface
{
public function __construct()
{
$this->name = 'my_module';
$this->version = '1.0.0';
$this->author = 'me';
$this->tab = 'front_office_features';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->description = ...
$this->displayName = ...
$this->confirmUninstall = ...
}
public function install()
{
if(!parent::install())
{
return false;
}
return true;
}
public function uninstall()
{
return(parent::uninstall());
}
public function renderWidget($hookName = null, array $configuration = [])
{
$this->smarty->assign($this->getWidgetVariables($hookName, $configuration));
return $this->display(__FILE__, 'views/templates/widget/my_template.tpl');
}
public function getWidgetVariables($hookName = null, array $configuration = [])
{
if($hookName === 'MyCustomHook')
{
$your_height_value, $your_iframe_value, $your_token_value... // Get the values depending on your logic
return [
'token' => $your_token_value;
'height' => $your_height_value;
'iframe' => $your__iframe_value;
];
}
}
In template file, just call the widget like:
{widget module='my_module' hook='myCustomHook'}
Upvotes: 1
Reputation: 1078
This is a builtin Prestashop hook and it has to stay there.
What you can do is register a custom hook of your own, like displayMyHookHere, here is a guide of how to do it hooks in PS 1.7+
Hook your module on it and display this in any spot on your page like {hook h='displayMyHookHere'}
Upvotes: 0