Jump to content

Recommended Posts

Bonjour

 

Je suis étudiant et j'ai commencer une petite suite d'exercice de mes profs sur Prestashop pour en maîtriser les base mais je me retrouve confronter à une erreur que je ne parvient pas à corriger (la fatigue joue peut être également). voilà j'ai générer un module à l'aide de : https://validator.prestashop.com/generator

 

après cela j'ai crée un fichier display.tpl dans monmodule/views/templates/hook

 

mais je ne parviens à l’appeler par monmodule.php à la racine de monmodule avec :

return $this->display(_FILE_, 'display.tpl');

je vous donne monmodule.php au complet si jamais l'erreur est lié.

<?php

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

class Monmodule extends Module{
    protected $config_form = false;

    public function __construct(){
        $this->name = 'monmodule';
        $this->tab = 'others';
        $this->version = '1.6.1';
        $this->author = 'Antoine Barbet';
        $this->need_instance = 0;

        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('monmodule');
        $this->description = $this->l('Ceci est une description');

        $this->confirmUninstall = $this->l('');

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

    public function install(){
        Configuration::updateValue('MONMODULE_LIVE_MODE', false);

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

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

        return parent::uninstall();
    }

    public function getContent(){

        if (((bool)Tools::isSubmit('submitMonmoduleModule')) == 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();
    }

    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 = 'submitMonmoduleModule';
        $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()));
    }

    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' => 'MONMODULE_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' => 'MONMODULE_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'MONMODULE_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    protected function getConfigFormValues(){
        return array(
            'MONMODULE_LIVE_MODE' => Configuration::get('MONMODULE_LIVE_MODE', true),
            'MONMODULE_ACCOUNT_EMAIL' => Configuration::get('MONMODULE_ACCOUNT_EMAIL', '[email protected]'),
            'MONMODULE_ACCOUNT_PASSWORD' => Configuration::get('MONMODULE_ACCOUNT_PASSWORD', null),
        );
    }


    protected function postProcess()
    {
        $form_values = $this->getConfigFormValues();

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


    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 hookHeader(){
        $this->context->controller->addJS($this->_path.'/views/js/front.js');
        $this->context->controller->addCSS($this->_path.'/views/css/front.css');
    }

    public function hookDisplayFooter(){
        return $this->display(_FILE_, 'display.tpl');
    }
}

help svp ça fais 2H que j'essaye de faire ce module mais rien à faire.

 

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...