Jump to content

hookDisplayBeforeCarrier($what???)


mopi

Recommended Posts

Bonjour  ;) 

Ca ressemble vraiment a un bug ! 

Avez vous testé les paramètres passer au hook hookDisplayBeforeCarrier($param) ? 

Moi j'ai ca, Sur une base PrestaShop 1.7.7  fraichement installer en local, sans thème particulier et sous PHP 7.14

array:3 [▼
  "cart" => Cart {#120 ▶}
  "cookie" => Cookie {#18 ▶}
  "altern" => 1
]

 

  Suivant la doc PrestaShop 1.7.7.0,  et historiquement, devrais  correspondre a ca : 

<?php
array(
    'carriers' => array(
        array(
            'name' => (string) Name,
            'img' => (string) Image URL,
            'delay' => (string) Delay text,
            'price' =>  (float) Total price with tax,
            'price_tax_exc' => (float) Total price without tax,
            'id_carrier' => (int) intified option delivery identifier,
            'id_module' => (int) Module ID
    )),
    'checked' => (int) intified selected carriers,
    'delivery_option_list' => array(array(
        0 => array( // First address
            '12,' => array( // First delivery option available for this address
                 carrier_list => array(
                     12 => array( // First carrier for this option
                         'instance' => Carrier Object,
                         'logo' => <url to the carrier's logo>,
                         'price_with_tax' => 12.4, // Example
                         'price_without_tax' => 12.4, // Example
                         'package_list' => array(
                             1, // Example
                             3, // Example
                          ),
                     ),
                 ),
                 is_best_grade => true, // Does this option have the biggest grade (quick shipping) for this shipping address
                 is_best_price => true, // Does this option have the lower price for this shipping address
                 unique_carrier => true, // Does this option use a unique carrier
                 total_price_with_tax => 12.5,
                 total_price_without_tax => 12.5,
                 position => 5, // Average of the carrier position
             ),
         ),
     )),
     'delivery_option' => array(
         '<id_address>' => Delivery option,
         ...
     )
);


 

ce qui me pose un sacret problème ! 

j'ai chercher sur google un moment , tester plusieurs chose, réinstaller une version de Prestashop.

j'avoue ne pas comprendre . Est-ce un bug ?

 

 

 

 

Edited by mopi (see edit history)
Link to comment
Share on other sites

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

Edited by mopi (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

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