如何在 prestashop 1.7 中显示我的管理选项卡?

how to show my admin tab in prestashop 1.7?

我在 ps 1.6 中成功显示了我的管理选项卡,但它没有出现在 1.7 中,这是我的代码:

  public function installTab()  {
    $tab = new Tab();
    $tab->id_parent = 0;
    //$tab->id_parent = (int)Tab::getIdFromClassName('AdminCatalog');
    $tab->name = array();
    foreach (Language::getLanguages(true) as $lang) {
        $tab->name[$lang['id_lang']] = 'Scan des codes barre';
      }
    $tab->class_name = 'AdminBarCodeGenerator';
    $tab->module = $this->name;
    $tab->active = 1;
    return $tab->add();

}

和我的控制器的方法:

 public function __construct(){
    $this->bootstrap = true;
    $this->display='';
    $this->context = Context::getContext();
    return parent::__construct();

}

   public function renderList()

{

$scan_form=$this->renderForm2();
$this->context->smarty->assign('scan_form',$scan_form);
return $this->context->smarty->fetch(_PS_MODULE_DIR_.'barcode/views/templates/admin/tabs/scan.tpl');

}

请问 ps 1.7 中有具体的处理方法吗?

你必须这样做;

public function installTab()
{
    $tab = new Tab();
    $tab->active = 1;
    $tab->class_name = "NewsletterBuildingConfig";
    $tab->name = array();
    foreach (Language::getLanguages(true) as $lang) {
        $tab->name[$lang['id_lang']] = "Newsletter Settings";
    }
    $tab->id_parent = (int)Tab::getIdFromClassName('AdminParentThemes');
    $tab->module = $this->name;
    $tab->add();

    return true;
}

确保在 install() 函数中安装您的选项卡

$this->installTab('AdminParentThemes', 'NewsletterBuildingConfig', 'Newsletter Settings')

然后是您的管理控制器 NewsletterBuildingConfig.php

class NewsletterBuildingConfigController extends ModuleAdminController
{
    public function __construct()
    {
        $this->bootstrap = true;
        parent::__construct();
        // Redirect is not needed, you can display your tpl file here
        Tools::redirect(
        $this->context->link->getAdminLink('AdminModules', true).'&configure=newsletterbuilderandsender'
        );
}

}

我认为问题可能在于将父 ID 设置为 0。尝试:

$tab->id_parent = (int)Tab::getIdFromClassName('DEFAULT');

此外,您的 class 名称应以 Admin

开头

在新版本中很容易。

在模块的主 php 文件中 (yourmodule.php):

public $tabs = [
    [
        'name' => 'Merchant Expertise', // One name for all langs
        'class_name' => 'AdminGamification',
        'visible' => true,
        'parent_class_name' => 'ShopParameters',
    ],
];

名称可以是语言数组:

[
    'en' => 'Some text',
    'fa' => 'متن تست'
]

如果要显示选项卡事件 1.6 和 1.7,请使用此结构:

对于 1.7:

 class mymodule extends Module
{
    public $tabs = array(
        array(
            'name' => 'My Tab Name',
            'class_name' => 'AdminMyModuleNameControllerName',
            'visible' => true,
            'parent_class_name' => 'AdminParentModulesSf',
        ),
    );
....

对于 1.6:

    public function install()
    { ...

     if(!version_compare(_PS_VERSION_, '1.7', '>=')){
        foreach ($this->tabs as $tabItem) {
                            $tab = new Tab();
                            $tab->name = array();
                            foreach (Language::getLanguages(true) as $lang) {
                                $tab->name[$lang['id_lang']] = $tabItem['name'];
              
                  }
                        $tab->class_name = $tabItem['class_name'];
                        $tab->id_parent = Tab::getIdFromClassName($tabItem['parent_class_name']);
                        $tab->module = $this->name;
                        $tab->position = 0;
                        $tab->active = $tabItem['visible'] ? 1 : 0;
                        $tab->save();
                    }
    }
    ...
}