Jump to content

Prestashop Validator Main class not found.


Recommended Posts

Bonjour,

 

Je tourne en rond depuis deux jours, sur google et les forums sans trouver de réponse à mon soucis... Je viens d'écrire un petit module simple et quand j'essaye de le passer sur Validator j'ai ce message assez peu clair pour moi : Main class not found.

 

Quelqu'un peut-il m'éclairer ? Quelle est donc cette main class ?

 

D'avance merci :)

F.

Link to comment
Share on other sites

C'était de l'humour informatique^^

 

Sérieusement, vous écrivez un module et vous ne savez pas ce que "main class" signifie ?

 

Quelles sont les premières lignes de votre fichier principal du module ? (Qui doit avoir le même nom que le répertoire qui le contient)

Link to comment
Share on other sites

Bonjour,

 

Si je sais ce que Main Class signifie, ce que je ne sais pas c'est ce que signifie ce message d'erreur sur Validator...

 

Les premières lignes de mon fichier du même nom que le module et que le répertoire qui le contient sont :


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

	
class blockcompteurarbre extends Module
{
	public function __construct()
	{
		$this->name = 'blockcompteurarbre';

Pour ce qui est de l'humour, je n'ai jamais gouté la condescendance des experts d'un domaine particulier à l'égard des généralistes qui ne se cantonnent pas à un sujet...

Link to comment
Share on other sites

Alors un peu de lecture :) http://doc.prestashop.com/display/PS16/Creating+a+first+module

 

 

The main class

The main file must contain the module's main class (along with other classes if needed). PrestaShop uses Object-Oriented programming, and so do its modules.

That class must bear the same name as the module and its folder, in CamelCase (see http://en.wikipedia.org/wiki/CamelCase). In our example: MyModule.
Furthermore, that class must extend the Module class, in order to inherit all its methods and attributes.

Link to comment
Share on other sites

Merci, mais je l'avais déjà lu...

 

J'ai beau le lire dans tous les sens, je ne vois pas mon erreur... Mon répertoire s'appelle bien blockcompteurarbre, mon fichier php s'appelle aussi blockcompteurarbre.php et mon module s'appelle aussi blockcompteurarbre...

 

Est-ce à dire qu'il me faut mettre des majuscules et renommer le tout en BlockCompteurArbre ?

Link to comment
Share on other sites

C'est pourtant clair, mais je vais vous l'écrire en français alors:

Le nom de la classe doit être le même que celui du fichier et du répertoire EN CAMELCASE (voir: https://fr.wikipedia.org/wiki/CamelCase).
Dans nontre exemple: MonModule

Mais c'est bien précisé : Le nom de la classe (ceux du répertoire et fichier restent en minuscules)

 

Si ce n'est toujours pas clair pour vous je ne sais pas comment vous l'expliquer autrement :(

Link to comment
Share on other sites

OK, donc mon répertoire reste blockcompteurarbre, mon module reste blockcompteurarbre, mon php reste blockcompteurarbre.php mais ma class devient BlockCompteurArbre, j'ai bon ?


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

	
class BlockCompteurArbre extends Module
{
	public function __construct()
	{
		$this->name = 'blockcompteurarbre';
		$this->tab = 'front_office_features';
		$this->version = '1.0.2';

Ben... même comme ça Validator m'indique toujours la même erreur :'(

Link to comment
Share on other sites

Bonjour ! 

 

Je me suis jamais frotté au Validateur mais tu as essayé ça Blockcompteurarbre ?

 

Bon courage ! :)

 

Bonjour,

 

Merci pour ta réponse, oui, je crois que j'ai testé toutes les combinaisons : Blockcompteurarbre, BlockCompteurarbre, BlockCompteurArbre... rien n'y fait... :'(

Link to comment
Share on other sites

Le code Presta :

 

<?php
/**
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    PrestaShop SA <[email protected]>
*  @copyright 2007-2015 PrestaShop SA
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

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

class Essai extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'Essai';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'Internet D2 Savoie';
        $this->need_instance = 0;

        /**
         * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
         */
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('Module d\'essai');
        $this->description = $this->l('Ceci est une description pour générer un module de test afin de valider le fonctionnement du système !');

        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
    }

    /**
     * Don't forget to create update methods if needed:
     * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
     */
    public function install()
    {
        Configuration::updateValue('ESSAI_LIVE_MODE', false);

        return parent::install() &&
            $this->registerHook('header') &&
            $this->registerHook('backOfficeHeader') &&
            $this->registerHook('displayHeader') &&
            $this->registerHook('displayHome');
    }

    public function uninstall()
    {
        Configuration::deleteByName('ESSAI_LIVE_MODE');

        return parent::uninstall();
    }

    /**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitEssaiModule')) == true) {
            $this->postProcess();
        }

        $this->context->smarty->assign('module_dir', $this->_path);

        $output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');

        return $output.$this->renderForm();
    }

    /**
     * Create the form that will be displayed in the configuration of your module.
     */
    protected function renderForm()
    {
        $helper = new HelperForm();

        $helper->show_toolbar = false;
        $helper->table = $this->table;
        $helper->module = $this;
        $helper->default_form_language = $this->context->language->id;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);

        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitEssaiModule';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
            .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');

        $helper->tpl_vars = array(
            'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id,
        );

        return $helper->generateForm(array($this->getConfigForm()));
    }

    /**
     * Create the structure of your form.
     */
    protected function getConfigForm()
    {
        return array(
            'form' => array(
                'legend' => array(
                'title' => $this->l('Settings'),
                'icon' => 'icon-cogs',
                ),
                'input' => array(
                    array(
                        'type' => 'switch',
                        'label' => $this->l('Live mode'),
                        'name' => 'ESSAI_LIVE_MODE',
                        'is_bool' => true,
                        'desc' => $this->l('Use this module in live mode'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => true,
                                'label' => $this->l('Enabled')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => false,
                                'label' => $this->l('Disabled')
                            )
                        ),
                    ),
                    array(
                        'col' => 3,
                        'type' => 'text',
                        'prefix' => '<i class="icon icon-envelope"></i>',
                        'desc' => $this->l('Enter a valid email address'),
                        'name' => 'ESSAI_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'ESSAI_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'ESSAI_LIVE_MODE' => Configuration::get('ESSAI_LIVE_MODE', true),
            'ESSAI_ACCOUNT_EMAIL' => Configuration::get('ESSAI_ACCOUNT_EMAIL', '[email protected]'),
            'ESSAI_ACCOUNT_PASSWORD' => Configuration::get('ESSAI_ACCOUNT_PASSWORD', null),
        );
    }

    /**
     * Save form data.
     */
    protected function postProcess()
    {
        $form_values = $this->getConfigFormValues();

        foreach (array_keys($form_values) as $key) {
            Configuration::updateValue($key, Tools::getValue($key));
        }
    }

    /**
    * Add the CSS & JavaScript files you want to be loaded in the BO.
    */
    public function hookBackOfficeHeader()
    {
        if (Tools::getValue('module_name') == $this->name) {
            $this->context->controller->addJS($this->_path.'views/js/back.js');
            $this->context->controller->addCSS($this->_path.'views/css/back.css');
        }
    }

    /**
     * Add the CSS & JavaScript files you want to be added on the FO.
     */
    public function hookHeader()
    {
        $this->context->controller->addJS($this->_path.'/views/js/front.js');
        $this->context->controller->addCSS($this->_path.'/views/css/front.css');
    }

    public function hookDisplayHeader()
    {
        /* Place your code here. */
    }

    public function hookDisplayHome()
    {
        /* Place your code here. */
    }
}

Mon code :
 

<?
/*
* Bloc de page d'accueil permettant de compter et d'afficher le nombre d'arbre planté via le module reforest action
*/

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

	
class Blockcompteurarbre extends Module
{
	public function __construct()
	{
		$this->name = 'blockcompteurarbre';
		$this->tab = 'front_office_features';
		$this->version = '1.0.2';
		$this->author = 'Internet D2 Savoie';
		$this->need_instance = 0;
		$this->bootstrap = true;

		parent::__construct();

		$this->displayName = $this->l('Reforest\'Action tree counter block');
		$this->description = $this->l('Add a block in addition to the Reforest\'Action module on your home page !');
		$this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6.99.99');
	}

	public function install()
	{
		return (parent::install() && $this->registerHook('displayRightColumn') && $this->registerHook('hookDisplayHome') && $this->registerHook('displayTop') && $this->registerHook('displayHeader'));
	}
    public function uninstall()
    {
        Configuration::deleteByName('BLOCKCOMPTEURARBRE_LIVE_MODE');

        return parent::uninstall();
    }

    /**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitBlockcompteurarbreModule')) == true) {
            $this->postProcess();
        }

        $this->context->smarty->assign('module_dir', $this->_path);

        $output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');

        return $output.$this->renderForm();
    }

    /**
     * Create the form that will be displayed in the configuration of your module.
     */
    protected function renderForm()
    {
        $helper = new HelperForm();

        $helper->show_toolbar = false;
        $helper->table = $this->table;
        $helper->module = $this;
        $helper->default_form_language = $this->context->language->id;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);

        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitBlockcompteurarbreModule';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
            .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');

        $helper->tpl_vars = array(
            'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id,
        );

        return $helper->generateForm(array($this->getConfigForm()));
    }

    /**
     * Create the structure of your form.
     */
    protected function getConfigForm()
    {
        return array(
            'form' => array(
                'legend' => array(
                'title' => $this->l('Settings'),
                'icon' => 'icon-cogs',
                ),
                'input' => array(
                    array(
                        'type' => 'color',
                        'name' => 'BLOCKCOMPTEURARBRE_TEXT_COLOR',
						'desc' => $this->l('Choose color for the text - Enter an hexadecimal code'),
                        'label' => $this->l('Text color'),
						'data-hex' => true,
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'BLOCKCOMPTEURARBRE_TEXT_COLOR' => Configuration::get('BLOCKCOMPTEURARBRE_TEXT_COLOR', null),
        );
    }

    /**
     * Save form data.
     */
    protected function postProcess()
    {
        $form_values = $this->getConfigFormValues();

        foreach (array_keys($form_values) as $key) {
            Configuration::updateValue($key, Tools::getValue($key));
        }
    }

    /**
    * Add the CSS & JavaScript files you want to be loaded in the BO.
    */
    public function hookBackOfficeHeader()
    {
        if (Tools::getValue('module_name') == $this->name) {
            $this->context->controller->addJS($this->_path.'views/js/back.js');
            $this->context->controller->addCSS($this->_path.'views/css/back.css');
        }
    }
	
	
	public function hookDisplayRightColumn($params)
	{
	 if (!$this->isCached('blockcompteurarbre.tpl', $this->getCacheId())) {
		$this->smarty->assign('BLOCKCOMPTEURARBRE_TEXT_COLOR', Configuration::get('BLOCKCOMPTEURARBRE_TEXT_COLOR'));
		$this->smarty->assign('nbrarbres', blockcompteurarbreClass::comptearbre());
		}
		return $this->display(__FILE__, 'views/templates/front/blockcompteurarbre.tpl');
	}
	public function hookDisplayHome($params)
	{
		return $this->hookDisplayRightColumn($params);
	}
	public function hookdisplayTop($params)
	{
		return $this->hookDisplayRightColumn($params);
	}

	public function hookDisplayHeader($params)
	{
	 	$this->context->controller->addCss($this->getPathUri().'views/css/front.css');
	}

}

class BlockcompteurarbreClass extends ObjectModel
{
		public static function comptearbre() {
				  $sql = "SELECT COUNT(*)FROM ps_reforestaction";
				  $arbres = Db::getInstance()->getValue($sql);
				  return $arbres;
		}

}

Link to comment
Share on other sites

Merci. C'est curieux, ils mettent des majuscules partout...

 

1) Essaye d'enlève ta majuscule au nom de ta classe Blockcompteurarbre (avec comme nom de fichier blockcompteurarbre.php) ?

2) Si ça marche pas, essaye de mettre une majuscule comme eux (au module, au fichier, à la classe, à l'attribut name de ton module). 

 

Bon courage :)

Link to comment
Share on other sites

Merci pour ton aide...

 

J'ai bien peur d'avoir essayé toutes les combinaisons possibles... Je viens d'utiliser Prestashop Generator pour comparer... et tout me semble bon... le module "vide" créé par le Generator passe bien dans Validator alors que le mien non... :'(

 

Je n'y comprends rien... Et pourtant le module fonctionne correctement...

Link to comment
Share on other sites

Essayez de remplacer la toute première ligne, à savoir le <? par <?php et renvoyez le module au validateur, pour voir.

 

 

Euh... Vous êtes un génie !!! Mille mercis, je n'aurais jamais pensé que cela pouvait poser problème !!!

 

Cela fonctionne effectivement :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...