telnett Posted March 16, 2017 Share Posted March 16, 2017 So, with displayProductTab and displayProductTabContent removed, how do we go about squeezing in new tabs on the product vew page? Link to comment Share on other sites More sharing options...
rocky Posted March 16, 2017 Share Posted March 16, 2017 Use the new productExtraContent hook like this: public function hookDisplayProductExtraContent($params) { $productExtraContent = new ProductExtraContent(); $productExtraContent->setTitle($this->l('Gallery')); $productExtraContent->setContent($this->context->smarty->fetch( 'module:nc_gallery/views/templates/front/tab_content.tpl' )); return array($productExtraContent); } This code is similar to what I have in my Image/Video Gallery module to create a "Gallery" tab and load the content from tab_content.tpl. Link to comment Share on other sites More sharing options...
telnett Posted March 16, 2017 Author Share Posted March 16, 2017 Use the new productExtraContent hook like this: public function hookDisplayProductExtraContent($params) { $productExtraContent = new ProductExtraContent(); $productExtraContent->setTitle($this->l('Gallery')); $productExtraContent->setContent($this->context->smarty->fetch( 'module:nc_gallery/views/templates/front/tab_content.tpl' )); return array($productExtraContent); } This code is similar to what I have in my Image/Video Gallery module to create a "Gallery" tab and load the content from tab_content.tpl. Thank you for your quick and accurate response! With this, I ended up having "mod_fcgid: stderr: PHP Fatal error: Class 'ProductExtraContent' not found ..." written to my error_log. Obviously I was still missing something, but since you got me on the right track, here is what worked for me: public function hookdisplayProductExtraContent($params) { $array = array(); $array[] = (new PrestaShop\PrestaShop\Core\Product\ProductExtraContent()) ->setTitle('tittle') ->setContent('content'); return $array; } Hope this thread will be useful for future learners! Link to comment Share on other sites More sharing options...
rocky Posted March 16, 2017 Share Posted March 16, 2017 Sorry, I forgot to mention you should add the following to the top of the file so my code works above: use PrestaShop\PrestaShop\Core\Product\ProductExtraContent; 1 Link to comment Share on other sites More sharing options...
polaije Posted October 21, 2017 Share Posted October 21, 2017 Hi, I come in this discussion because I need to know where you place your function, is it in one module or do you override Something. Sorry my question is perhaps stupid but I am new in PS development. Jean Link to comment Share on other sites More sharing options...
rocky Posted October 23, 2017 Share Posted October 23, 2017 (edited) It should be in the main module file. For example, modules/nc_gallery/nc_gallery.php in my module. Add the use line to the top of the file and the hookDisplayProductExtraContent function anywhere after the class line and before the last }. Also, don't forget to register the hook in the install() function using the code $this->registerHook('displayProductExtraContent') Edited October 23, 2017 by rocky (see edit history) Link to comment Share on other sites More sharing options...
polaije Posted October 29, 2017 Share Posted October 29, 2017 Thanks it's ok now ! Jean Link to comment Share on other sites More sharing options...
veijari Posted April 2, 2020 Share Posted April 2, 2020 On 3/16/2017 at 12:09 PM, rocky said: Use the new productExtraContent hook like this: public function hookDisplayProductExtraContent($params) { $productExtraContent = new ProductExtraContent(); $productExtraContent->setTitle($this->l('Gallery')); $productExtraContent->setContent($this->context->smarty->fetch( 'module:nc_gallery/views/templates/front/tab_content.tpl' )); return array($productExtraContent); } This code is similar to what I have in my Image/Video Gallery module to create a "Gallery" tab and load the content from tab_content.tpl. @rocky Hey we are new to prestashop developing. We would like to show our custom product info on the front end, same as features and attributes. We have a module and we are implementing your code, but nothing appears to the front end. We have disabled cache and cleared, but it didn't work. Is there something missing, do we have to invoke this hook elsewhere? Link to comment Share on other sites More sharing options...
rocky Posted April 3, 2020 Share Posted April 3, 2020 After adding the hookDisplayProductExtraContent($params) function to the module, did you transplant it into the displayProductExtraContent hook on the "Design > Positions > Transplant a module" tab? Link to comment Share on other sites More sharing options...
veijari Posted April 3, 2020 Share Posted April 3, 2020 6 hours ago, rocky said: After adding the hookDisplayProductExtraContent($params) function to the module, did you transplant it into the displayProductExtraContent hook on the "Design > Positions > Transplant a module" tab? @rocky Hey we got it working! Now we are struggling to show this info on the backend. There seems to be a similar hook DisplayAdminProductsExtra($params), but it doesn't seem to follow the same logic as front end. Do you have a solution for this? Link to comment Share on other sites More sharing options...
rocky Posted April 3, 2020 Share Posted April 3, 2020 (edited) Here's the function I use in my Image/Video Gallery module (modules/nc_gallery/nc_gallery.php): public function hookDisplayAdminProductsExtra($params) { if (isset($params['id_product']) && (int)$params['id_product']) { $controller = new AdminNCGalleryGalleriesController(); $this->context->smarty->assign('form', $controller->renderProductForm((int)$params['id_product'])); return $this->display(__FILE__, 'views/templates/admin/tab.tpl'); } } And a simplified version of the renderProductForm function that displays a multi-language text field on the configuration page (modules/nc_gallery/controllers/admin/AdminNCGalleryGalleriesController.php): public function renderProductForm($id_product) { if ((int)$id_product <= 0) { return; } $fields_value = []; $product_tab = null; $id_product_tab = (int)NCGalleryProductTab::getTabForProduct((int)$id_product); if ($id_product_tab) { $product_tab = new NCGalleryProductTab((int)$id_product_tab); $fields_value['nc_gallery_name'] = []; foreach (Language::getLanguages(false) as $language) { if (is_array($product_tab->name) && isset($product_tab->name[(int)$language['id_lang']]) && $product_tab->name[(int)$language['id_lang']] != '') { $fields_value['nc_gallery_name'][(int)$language['id_lang']] = $product_tab->name[$language['id_lang']]; } else { $fields_value['nc_gallery_name'][(int)$language['id_lang']] = Configuration::get('NC_GALLERY_DEFAULT_TAB_TITLE', (int)$language['id_lang']); } } } else { foreach (Language::getLanguages(false) as $language) { $fields_value['nc_gallery_name'][(int)$language['id_lang']] = Configuration::get('NC_GALLERY_DEFAULT_TAB_TITLE', (int)$language['id_lang']); } } $this->fields_form = [ 'input' => [ [ 'type' => 'text', 'label' => $this->l('Title'), 'name' => 'nc_gallery_name', 'hint' => $this->l('The tab text displayed on the product page'), 'required' => true, 'lang' => true, 'class' => 'form-control', ], ], ]; $this->fields_form = [['form' => $this->fields_form]]; $helper = new HelperForm($this); $this->setHelperDisplay($helper); $helper->languages = Language::getLanguages(); $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->fields_value = $fields_value; $helper->submit_action = $this->submit_action; $helper->tpl_vars = $this->getTemplateFormVars(); return $helper->generateForm($this->fields_form); } And in modules/nc_gallery/views/templates/admin/tab.tpl: <input type="hidden" name="submitted_tabs[]" value="nc_gallery" /> {$form} I hope this helps. Edited April 3, 2020 by rocky (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now