Jump to content
pixeliza

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Hi,

 

I'm creating module to add additional tab into edit product page called "Instructiuons". I have overrided AdminProductsController, but i have problems with tab tpl file, i dont know how to install it by module. It must be like "SEO" tab and ect. Can you help?

Edited by rytiz2873 (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


Link to post
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....

Share this post


Link to post
Share on other sites

Thanks for the comment anyway.

 

I'm still working on it and if I come up with a solution I'll post that here.

  • Like 1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More