Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prestashop 1.7 unable to display custom module

I'm trying prestashop 1.7 and I have an issue with the creation of custom modules. I have created a folder "mymodule" inside the "modules" folder, and, as it is indicate in the documentation I've created a simple mymodule.php file in it :

<?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');
  }
}

?>

Then I go on the administration page under "modules" -> "modules & services" on the "installed module" tab, but I can't find my module...

What error am I doing?

Thanks

Xavier

like image 662
xavatic Avatar asked Nov 28 '22 22:11

xavatic


2 Answers

Your steps are all right. To make a reminder, to create a 'custom' module we should do:

  1. Create a folder in modules folder, e.g. named `mycustommodule`
  2. Create a php file named like the folder, e.g. `mycustommodule.php`
  3. Then the "bootstrap" class (and construct) should be like this:
<?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 */
    }
}
?>

Then for prestashop 1.7.x.x you have to go in Modules and in the Selection tab click on 'Categories' and find your module (remember the $this->tab snippet?)

Categories menu

otherwise you can find it by searching:

Search input

like image 197
marsaldev Avatar answered Dec 08 '22 00:12

marsaldev


Today I encountered the same problem in Prestashop 1.7.6.1. Found 2 solutions to the problem:

  1. Zip your module and upload it using Prestashop backoffice. Not good if for example you use git to upload changes. So I keep searching, and found solution no 2

  2. If you create a custom module it appears in Module -> Catalog not in Modules -> Modules & Services tab... Very strange and counter intuitive behavior. After you install this module everything works as expected.

like image 32
Marcin Nowak Avatar answered Dec 07 '22 22:12

Marcin Nowak