Thứ Ba, 2 tháng 8, 2011

How to add tab in back office - Prestashop

Hi!
I will show you how to add tab in back office - Prestashop.
1. create folder 'addtabexample'.
2. create file 'addtabexample.php' and write following code in this file:
<?php
class Addtabexample extends Module
{

function __construct()
{
$this->name = 'addtabexample';
$this->displayName = $this->l('Add tab example');
$this->description = $this->l('How to add tab in back office - prestashop');
$this->version = '1.0';
$this->tab = 'front_office_features';

parent::__construct();
}

function install()
{
if (!parent::install()||!installModuleTab('AdminAddtabexample', 'Tab example', 2))
return false;
return true;
        }
        function uninstall()
        {
               if (!parent::unistall()||!uninstallModuleTab('AdminAddtabexample'))
                   return false;
               return true;
        }

        // add new tab

function installModuleTab($tabClass, $tabName, $id_parent)
{
$tab = new Tab();

$langs = Language::getLanguages();
foreach ($langs as $lang)
{
$tab->name[$lang['id_lang']] = $tabName;
}

$tab->class_name = $tabClass;
$tab->module = $this->name;
$tab->id_parent = $id_parent;

if (!$tab->save())
return false;

return true;
}
// delete tab
function uninstallModuleTab($tabClass)
{
$idTab = Tab::getIdFromClassName($tabClass);
if($idTab != 0)
{
  $tab = new Tab($idTab);
  $tab->delete();
  return true;
}
return false;
}


}

3. create file AdminAddtabexample.php
<?php
require_once dirname(__FILE__).'/../../classes/AdminTab.php';
class AdminAddtabexample extends AdminTab
{
    function display()
   {
        echo 'Add Tab';
   }
}

Thank you for your time, Please feel free to ask any question and feedback.

Không có nhận xét nào:

Đăng nhận xét