Jump to content

How to create a new tab Prestashop 1.7 (hookDisplayAdminProductsExtra)


widepresta

Recommended Posts

How to create a new tab Prestashop 1.7 ?

 

Prestashop 1.6

public function hookDisplayAdminProductsExtra()
{
     $this->context->smarty->assign(array(
         'id_product' => Tools::getValue('id_product'),
         'id_lang' => $this->context->language->id,
         'languages' => Language::getLanguages(),
         'default_language' => $this->default_language,
     ));

     return $this->display(__FILE__, 'views/templates/admin/tab.tpl');
}

In the new version also creates a new tab...

 

 

But how to connect file tab.html.twig ?

Transfer variables with the value of ?

 

Thanks.

 

Link to comment
Share on other sites

 

example:

public function hookDisplayAdminProductsExtra($params)
{
$this->context->smarty->assign(array('id_product' => $params['id_product']));
return $this->context->smarty->fetch('module:MODULE_NAME/views/tab.tpl');
}

 

Thanks for your reply

 

I would like to include file:  tab.html.twig

 

and use

 

use Symfony\Component\Form\FormBuilderInterface;

use Symfony\Component\Form\FormEvents;

use Symfony\Component\Form\FormEvent;

use Symfony\Component\Form\FormError;

 

Symfony how to connect to the module?

Edited by widepresta (see edit history)
Link to comment
Share on other sites

How to create form_widget?

 

For example the fields of product settings

src\PrestaShopBundle\Resources\views\Admin\Product\form.html.twig

 

example:

 

name product

form_widget(form.step1.name) 

I would like a new field in the new tab to create in this way

 

or short description

 form_widget(form.step1.description_short) 
Edited by widepresta (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

I'm do so

public function hookDisplayAdminProductsExtra($params){
		 
		$id_product = (int)Tools::getValue('id_product', $params['id_product']);
		$this->smarty->assign(array(
				'id_product' => $id_product,
				'xml' => $this->getCMLid($id_product),
				'xml_c' => $this->getCMLidComb($id_product),
				'varning' => $res
			));
			
			return $this->smarty->fetch('module:ecm_cmlid/views/templates/admin/ecm_cmlid.tpl');

	}

don't work. What am I doing wrong?

Link to comment
Share on other sites

I'm do so

public function hookDisplayAdminProductsExtra($params){
		 
		$id_product = (int)Tools::getValue('id_product', $params['id_product']);
		$this->smarty->assign(array(
				'id_product' => $id_product,
				'xml' => $this->getCMLid($id_product),
				'xml_c' => $this->getCMLidComb($id_product),
				'varning' => $res
			));
			
			return $this->smarty->fetch('module:ecm_cmlid/views/templates/admin/ecm_cmlid.tpl');

	}

don't work. What am I doing wrong?

 

 

 

Try this

public function hookDisplayAdminProductsExtra($params)
{
     $id_product = $params['id_product'];
     $res = false;
     $this->context->smarty->assign(array(
         'id_product' => $id_product,
	 'xml' => $this->getCMLid($id_product),
	 'xml_c' => $this->getCMLidComb($id_product),
	 'varning' => $res
     ));

     return $this->display(__FILE__, 'views/templates/admin/ecm_cmlid.tpl');
}

what is the $res ?

Link to comment
Share on other sites

Try this

public function hookDisplayAdminProductsExtra($params)
{
     $id_product = $params['id_product'];
     $res = false;
     $this->context->smarty->assign(array(
         'id_product' => $id_product,
	 'xml' => $this->getCMLid($id_product),
	 'xml_c' => $this->getCMLidComb($id_product),
	 'varning' => $res
     ));

     return $this->display(__FILE__, 'views/templates/admin/ecm_cmlid.tpl');
}

what is the $res ?

don't work...

$res is boolean variable

Link to comment
Share on other sites

I'm also struggling to get to this work in PrestaShop v1.7.0.3. I can't even get the "Module options" tab to show. It seems AdminProductsController::initFormModules is never called, so the displayAdminProductsExtra hook is never executed. :unsure:

 

I can't even find any modules that have it successfully working. Is it a bug in PrestaShop that needs to be fixed?

Link to comment
Share on other sites

Answer from PS support

 

 

I just tested and it's working. You just need to have at least one module hooked on displayAdminProductsExtra and the tab will appear.

It's not in the controller anymore, it's called in the twig file (https://github.com/PrestaShop/PrestaShop/blob/develop/src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig#L933)

What is your problem exactly?

but from me didn't help... any modules compatable 1.7 with hook DisplayAdminProductsExtra

:wacko:

Edited by savvato (see edit history)
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 1 year later...
  • 1 month later...

Hi

yes on the last version works but how to use the new UI-Kit helpers to use the same style? the smarty solution is good for the 1.6.x but not on the 1.7.x for that product page

I think should be used the same solution like this

https://devdocs.prestashop.com/1.7/modules/concepts/hooks/use-hooks-on-modern-pages/

 

but I do not know how to create a form with the various types of fields and use the new helpers
 

Link to comment
Share on other sites

  • 11 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...