Jump to content

How to create a new tab in the Edit product page ? - Figuring MVC out


Recommended Posts

Hi there, I'm trying to create a new tab in the Adminproducts page, the one your have information, price, SEO, etc.

 

I got to create the extra tab 'PaymentLimit' with the class override in /override/controllers/admin/AdminProductsController.php

 

 

class AdminProductsController extends AdminProductsControllerCore
{
protected $available_tabs = array(
 'Informations' => 0,
 'Pack' => 7,
 'VirtualProduct' => 8,
 'Prices' => 1,
 'Seo' => 2,
 'Associations' => 3,
 'Images' => 9,
 'Shipping' => 4,
 'Combinations' => 5,
 'Features' => 10,
 'Customization' => 11,
 'Attachments' => 12,
 'Quantities' => 6,
 'Suppliers' => 13,
 'Warehouses' => 14,
 'PaymentLimit' => 15
);


public function __construct()
{

...




// @since 1.5 : translations for tabs
$this->available_tabs_lang = array (
'Informations' => $this->l('Information'),
'Pack' => $this->l('Pack'),
'VirtualProduct' => $this->l('Virtual Product'),
'Prices' => $this->l('Prices'),
'Seo' => $this->l('SEO'),
'Images' => $this->l('Images'),
'Associations' => $this->l('Associations'),
'Shipping' => $this->l('Shipping'),
'Combinations' => $this->l('Combinations'),
'Features' => $this->l('Features'),
'Customization' => $this->l('Customization'),
'Attachments' => $this->l('Attachments'),
'Quantities' => $this->l('Quantities'),
'Suppliers' => $this->l('Suppliers'),
'Warehouses' => $this->l('Warehouses'),
'PaymentLimit' => $this->l('PaymentLimit'),
);


...

}


 

With this I create the PaymentLimit tab, but I can't get it to load the paymentlimit.tpl I have created in admin/themes/default/template/controllers/products.

 

 

 

Ok, I forgot to create the function in the override file to indicate the tpl :huh: , now the .tpl is showing.

 

public function initFormPaymentLimit($product)
{
….
}

 

I hope this helps somebody.

Edited by pixeliza (see edit history)
  • Like 3
Link to comment
Share on other sites

If you are writing a module you can use this code:

 

 //to install
    if( !$this->adminInstall()) return FALSE;
 //to uninstall
    $tab = new Tab(Tab::getIdFromClassName('AdminContactMultiShop'));
    if (!$tab->delete()) return false;

   private function adminInstall()
{
 if (!$idTab = Tab::getIdFromClassName('yourClassNameInModuleFolder')) {
  $tab = new Tab();
  $tab->class_name = 'yourClassNameInModuleFolder';
  $tab->module = 'yourmodulename';
  $tab->id_parent = 9;  //ID OF THE PARENT TAB, WE USE HARD CODED AS getIdFromClass parent did not work
  $languages = Language::getLanguages(false);
  foreach ($languages as $lang)
   $tab->name[$lang['id_lang']] = 'YourTabName';
  $res &= $tab->save();
  $tab->name[(int)(Configuration::get('PS_LANG_DEFAULT'))] = $this->l('yourClassNameInModuleFolder');
 }
 return TRUE;
}

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  • 4 weeks later...

Hello,

 

The post is really helpful and I was able to add a tab with ease. I'm doing this through module and currently I'm facing a problem here in placing the tpl file(like paymentlimit.tpl). Actually I don't know where to place that file in my module and now when I'm clicking on my custom tab it is giving me following error

 

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'C:\xampp\htdocs\prestashop\admin1/themes/default\template\PaymentLimit.tpl'' in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php

 

So please suggest me where and in which folders(in my module) I should place that tpl file.

Link to comment
Share on other sites

Hello Elpatron,

 

Thanks for the reply,

 

I was able to add and show the .tpl file by placing it in admin1/themes/default/template/controllers/products folder where rest of the tpl files for products tab page are placed. But thats not the standard place I think and I want to place that file in my module folder. I tried the link, you have suggested but still no progress.

 

In your first reply you have given some code, it will be very helpful if you shed some light on that,

 

FYI : I'm developing the module for 1.5

Link to comment
Share on other sites

Hello Elpatron,

 

Thanks for the reply,

 

I was able to add and show the .tpl file by placing it in admin1/themes/default/template/controllers/products folder where rest of the tpl files for products tab page are placed. But thats not the standard place I think and I want to place that file in my module folder. I tried the link, you have suggested but still no progress.

 

In your first reply you have given some code, it will be very helpful if you shed some light on that,

 

FYI : I'm developing the module for 1.5

 

Honestly I don't know if it would work the same for .tpl's as it did for a php form. In my module I used a php form. My tab for (PHP) resided in my module directory....Sorry I am not much more help....

Link to comment
Share on other sites

  • 2 months later...

I got it to work by moving the tpl file from my module folder to admin1/themes/default/template/controllers/products folder

I placed the code of moving file in module's installation function

 

hi , can you please explain how you did it step by step ?

Link to comment
Share on other sites

  • 4 weeks later...
×
×
  • Create New...