簡體   English   中英

Prestashop 1.7 無法顯示自定義模塊

[英]Prestashop 1.7 unable to display custom module

我正在嘗試 prestashop 1.7,但在創建自定義模塊時遇到問題。 我在“modules”文件夾中創建了一個文件夾“mymodule”,並且正如文檔中所示,我在其中創建了一個簡單的 mymodule.php 文件:

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

if (!defined('_PS_VERSION_'))
 exit;

class MyModule extends Module
{
  public function __construct()
  {
    $this->name = 'mymodule';
    $this->tab = 'front_office_features';
    $this->version = '1.0.0';
    $this->author = 'Firstname Lastname';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
    $this->bootstrap = true;

    parent::__construct();

    $this->displayName = $this->l('My module');
    $this->description = $this->l('Description of my module.');

    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

    if (!Configuration::get('MYMODULE_NAME'))      
      $this->warning = $this->l('No name provided');
  }
}

?>

然后我進入“模塊”->“模塊和服務”下的“已安裝模塊”選項卡下的管理頁面,但我找不到我的模塊...

我在做什么錯誤?

謝謝

澤維爾

你的步驟沒問題。 提醒一下,要創建一個“自定義”模塊,我們應該這樣做:

  1. 在模塊文件夾中創建一個文件夾,例如命名為`mycustommodule`
  2. 創建一個命名為文件夾的php文件,例如`mycustommodule.php`
  3. 那么“引導”類(和構造)應該是這樣的:
<?php
if (!defined('_PS_VERSION_'))
    exit;

class MyCustomModule extends Module
{
    public function __construct()
    {
        $this->name = 'mycustommodule'; /* This is the 'technic' name, this should equal to filename (mycustommodule.php) and the folder name */
        $this->tab = 'module type category'; /* administration, front_office_features, etc */
        $this->version = '1.0.0'; /* Your module version */
        $this->author = 'Firstname Lastname'; /* I guess it was clear */
        $this->need_instance = 0; /* If your module need an instance without installation */
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); /* Your compatibility with prestashop(s) version */
        $this->bootstrap = true; /* Since 1.6 the backoffice implements the twitter bootstrap */

        parent::__construct(); /* I need to explain that? */

        $this->displayName = $this->l('My module'); /* This is the name that merchant see */
        $this->description = $this->l('Description of my module.'); /* A short description of functionality of this module */

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); /* This is a popup message before the uninstalling of the module */
    }
}
?>

然后對於 prestashop 1.7.xx,您必須進入Modules並在Selection選項卡中單擊“類別”並找到您的模塊(還記得 $this->tab 片段嗎?)

類別菜單

否則你可以通過搜索找到它:

搜索輸入

今天我在 Prestashop 1.7.6.1 中遇到了同樣的問題。 找到了2個解決問題的方法:

  1. 壓縮您的模塊並使用 Prestashop 后台上傳。 例如,如果您使用 git 上傳更改,那就不好了。 所以我一直在尋找,並找到了解決方案 2

  2. 如果您創建自定義模塊,它會出現在模塊 -> 目錄中,而不是在模塊 -> 模塊和服務選項卡中... 非常奇怪且違反直覺的行為。 安裝此模塊后,一切都按預期工作。

我在 1.7.4 版本上遇到了同樣的問題

我通過在文件中注釋以下行解決了這個問題

\\src\\PrestaShopBundle\\Controller\\Admin\\ModuleController.php

$filters = new AddonListFilter();
 $filters->setType(AddonListFilterType::MODULE | AddonListFilterType::SERVICE);
 //    ->removeStatus(AddonListFilterStatus::UNINSTALLED);
 $installedProducts = $moduleRepository->getFilteredList($filters);

我不知道為什么我們看不到卸載的模塊

只需轉到模塊目錄而不是模塊管理器,您就會找到自定義模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM