Hello,
I am trying to do what you indicate in a Prestashop 1.7.5 (@Rolige), I have created a new module, but it does not work, I am not very clear where to place this line in the php.
$this->context->smarty->assign('all_combinations', (new Product($id_product))->getAttributeCombinations());
This is my php file code for my module:
<?php if(!defined('_PS_VERSION_')) exit; class extraInfo extends Module{ public function __construct() { $this->name = 'extra_info'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author ='pShark'; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.7.x.x', 'max' => _PS_VERSION_); $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Product - Extra Information'); $this->description = $this->l('Extra information in product page'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall the module?'); $this->templateFile = 'module:extra_info/views/templates/hook/extra_info.tpl'; } public function install() { return (parent::install() && $this->registerHook('displayHeader') && $this->registerHook('displayProductAdditionalInfo') ); $this->emptyTemplatesCache(); return (bool) $return; } public function hookDisplayHeader($params) { $this->context->smarty->assign('all_combinations', (new Product($id_product))->getAttributeCombinations()); $this->context->controller->registerStylesheet('modules-extraInfo', 'modules/'.$this->name.'/views/css/extra_info.css', ['media' => 'all', 'priority' => 150]); } public function uninstall() { $this->_clearCache('*'); if(!parent::uninstall() || !$this->unregisterHook('displayProductAdditionalInfo')) return false; return true; } public function hookDisplayProductAdditionalInfo() { return $this->display(__FILE__, 'views/templates/hook/extra_info.tpl'); } }
I have added the line to assign the smarty variable in hookDisplayHeader(), but I have tried to add it in hookDisplayProductAdditionalInfo() and __construct(), but it does not work.
Then in tpl file, I have placed the code that you indicated:
{foreach from=$all_combinations item=item} {$item.quantity} {/foreach}
The module loads in the hook that I have indicated perfectly (I have tried to place a text in the tpl and it appears), but it does not load the information of the combinations, I imagine that the smarty variable is not assigned correctly.
Does anyone know why it doesn't work? do you see something wrong in my code?
Regards!