Jump to content

Edit History

mopi

mopi

Pour etre complet , je rajoute le code de mon module de test, ainsi c'est assez simple de vérifier mes infos ;) 
Je sais que la fonction hookBeforeCarrier() n'existe pas , c'est hookdisplayBeforeCarrier() , mais je l'ai rajouter, histoire de tester si il n'y a pas un problème la dessus . 

Franchement, je désespère, si un de vous peut me dire que sur son prestashop 1.7.7 il a bien les bon paramètre dans le hookdisplayBeforeCarrier()  ca me permettrais d'avancer un peut ma recherche du coté du paramétrage . Si non c'est que c'est probablement un bug PrestaShop.

le test du Hook est très simple a faire 🙄 , n'importe quel module , tu rajoute

public function hookdisplayBeforeCarrier($param){
        dump('display');
        dump($param);
    }

tu vas dans position et tu accroche le hook hookdisplayBeforeCarrier et dans le front office, au niveau du choix des transporteur tu verra les variables ;) 

 

Mon code de test :, et je rajoute mon module de test en zip .  

<?php
/**

*/

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

class Testmodule extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'testmodule';
        $this->tab = 'administration';
        $this->version = '1.0.0';
        $this->author = 'lmcreation';
        $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('my test module');
        $this->description = $this->l('super module  super module  super module  super module  ');

        $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('TESTMODULE_LIVE_MODE', false);

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

    public function uninstall()
    {
        Configuration::deleteByName('TESTMODULE_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('submitTestmoduleModule')) == 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 = 'submitTestmoduleModule';
        $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' => 'TESTMODULE_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' => 'TESTMODULE_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'TESTMODULE_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'TESTMODULE_LIVE_MODE' => Configuration::get('TESTMODULE_LIVE_MODE', true),
            'TESTMODULE_ACCOUNT_EMAIL' => Configuration::get('TESTMODULE_ACCOUNT_EMAIL', '[email protected]'),
            'TESTMODULE_ACCOUNT_PASSWORD' => Configuration::get('TESTMODULE_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 hookdisplayBeforeCarrier($param){
        dump('display');
        dump($param);
    }
    
    // nimporte quoi, mais on ne sais jammais :
    public function hookBeforeCarrier($param){
       dump('hookBeforeCarrier');
        dump($param); 
    }
    
}

 

testmodule.zip

mopi

mopi

Pour etre complet , je rajoute le code de mon module de test, ainsi c'est assez simple de vérifier mes infos ;) 
Je sais que la fonction hookBeforeCarrier() n'existe pas , c'est hookdisplayBeforeCarrier() , mais je l'ai rajouter, histoire de tester si il n'y a pas un problème la dessus . 

Franchement, je désespère, si un de vous peut me dire que sur son prestashop 1.7.7 il a bien les bon paramètre dans le hookdisplayBeforeCarrier()  ca me permettrais d'avancer un peut ma recherche du coté du paramétrage . Si non c'est que c'est probablement un bug PrestaShop.

le test du Hook est très simple a faire 🙄 , n'importe quel module , tu rajoute

public function hookdisplayBeforeCarrier($param){
        dump('display');
        dump($param);
    }

tu vas dans position et tu accroche le hook hookdisplayBeforeCarrier et dans le front office, au niveau du choix des transporteur tu verra les variables ;) 

 

Mon code de test :, et je rajoute mon module de test en zip .  

<?php
/**

*/

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

class Testmodule extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'testmodule';
        $this->tab = 'administration';
        $this->version = '1.0.0';
        $this->author = 'lmcreation';
        $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('my test module');
        $this->description = $this->l('super module  super module  super module  super module  ');

        $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('TESTMODULE_LIVE_MODE', false);

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

    public function uninstall()
    {
        Configuration::deleteByName('TESTMODULE_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('submitTestmoduleModule')) == 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 = 'submitTestmoduleModule';
        $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' => 'TESTMODULE_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' => 'TESTMODULE_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'TESTMODULE_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'TESTMODULE_LIVE_MODE' => Configuration::get('TESTMODULE_LIVE_MODE', true),
            'TESTMODULE_ACCOUNT_EMAIL' => Configuration::get('TESTMODULE_ACCOUNT_EMAIL', '[email protected]'),
            'TESTMODULE_ACCOUNT_PASSWORD' => Configuration::get('TESTMODULE_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 hookdisplayBeforeCarrier($param){
        dump('display');
        dump($param);
    }
    
    // nimporte quoi, mais on ne sais jammais :
    public function hookBeforeCarrier($params){
       dump('hookBeforeCarrier');
        dump($param); 
    }
    
}

 

testmodule.zip

×
×
  • Create New...