ProductExtraContent hook missing urls variable in PrestaShop

I am using PrestaShop 1.7.5.0 and I am developing my theme using PS's Starter Theme (develop branch). I managed to cleanly override all the .tpl files I needed for HPP, but I am having trouble with PPB. In particular, I could get the ProductFooter and the blocksProductCart to work, but I couldn't do it with the ProductExtraContent. Basically, I don't receive any error, but the PPB tab is not rendered. To be sure, I also tried with the Classic theme, and I have the same problem. I tried to look into it and I think I understood what the issue is, although I do not have the solution.

From what I understand, this is the problematic part (ppb.php, function hookdisplayProductExtraContent, lines 836-)

foreach ($blocks as $tab => $value) {
$this->context->smarty->assign(array('blocks' => $this->prepareBlocksProducts(array($value))));
$this->context->smarty->assign('ppb_customtplpath', $this->return_ppb_customtplpath());
$ps17tabz[] = (new PrestaShop\PrestaShop\Core\Product\ProductExtraContent())->setTitle($value->name)->setContent($this->context->smarty->fetch('module:ppb/views/templates/hook/ProductExtraContent.tpl'));
}

I noticed that when I put very simple HTML content in productExtraContent.tpl, the tab is rendered correctly. However, when it contains a product miniature, it doesn't work. Doing some more debugging, it looks like when rendering the tab tpl, Smarty does not have access to $configuration$urls and $static_token (all used in the "add to cart" miniature section). Is there a way to give this variables to Smarty? I see they are all defined in FrontController.php, but I have no clue how to get their values from inside your module. Could you give me some info on how to proceed?

Thanks a lot in advance for your help

ProductExtraContent hook variables

Hello
Construction of productExtraContent hook is different than other hooks available in PrestaShop. 
It is because this hook is executed before the FrontController includes other variables to smarty template engine. Moreover function that implements hook to the module does not return contents in the same way as other hooks (it returns array[] with tab results instead). Because of this variables you mentioned are not included to smarty templates engine in productExtraContent hook.

Module is crafed to work only with features available in the module, so we do not included the other variables you mentioned to the smarty template engine, because these variables are not required for the module features. If you want to personalize the template file with own code etc. the only one way to add missing variables is a modification of function implemented to the module.

you mentioned that you added a line:
$this->context->smarty->assign('urls', $this->context->controller->getTemplateVarUrls()); // added line
inside foreach loop - i confirm that it is a proper way. But to avoid duplicated(or triplicated or more) variables addition - move the code before the <foreach> loop


something like:
if (isset($blocks) && Configuration::get('ppb_tabs') == 1) {
 if (count($blocks) > 0) {

  $this->context->smarty->assign('urls', $this->context->controller->getTemplateVarUrls());
  // other variables here

  foreach ($blocks as $tab => $value) {
  $this->context->smarty->assign(array('blocks' => $this->prepareBlocksProducts(array($value))));
  $this->context->smarty->assign('ppb_customtplpath', $this->return_ppb_customtplpath());
  $ps17tabz[] = (new PrestaShop\PrestaShop\Core\Product\ProductExtraContent())->setTitle($value->name)->setContent($this->context->smarty->fetch('module:ppb/views/templates/hook/ProductExtraContent.tpl'));
  }
 }
}

post is conntected to related products pro usage of productExtraContent hook











ProductExtraContent hook missing urls variable in PrestaShop ProductExtraContent hook missing urls variable in PrestaShop Reviewed by VEKIA on Wednesday, January 30, 2019 Rating: 5

No comments