Jump to content

Edit History

Alexandre Carette

Alexandre Carette

Salut, oui c'est possible, je t'ai fais un petit module rapidement

<?php
/**
* 2007-2020 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-2020 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 Baba_adress_customer_form extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'baba_adress_customer_form';
        $this->tab = 'administration';
        $this->version = '0.0.0';
        $this->author = 'Alexandre Carette';
        $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('baba_adress_customer_form');
        $this->description = $this->l('Allow to add adress in customer form.');

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

        return parent::install() &&
        $this->registerHook('actionObjectCustomerAddAfter') &&
        $this->registerHook('additionalCustomerFormFields');
    }

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

        return parent::uninstall() &&
        $this->unregisterHook('actionBeforeSubmitAccount') &&
        $this->unregisterHook('additionalCustomerFormFields');



    }

    /**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitBaba_adress_customer_formModule')) == 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 = 'submitBaba_adress_customer_formModule';
        $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' => 'BABA_ADRESS_CUSTOMER_FORM_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' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE', true),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL', '[email protected]'),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_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));
        }
    }

    public function hookActionObjectCustomerAddAfter(array $params)
    {

        $company = Tools::getValue('company');
      

        // On ajoute l'adresse du client à la création de l'objet customer
       // On instancie l'objet Customer qui vient de créer son compte
       $customer = new Customer((int)$params['object']->id);
       // On ajoute le nom de sa compagnie
       $customer->company = $company;
       // on update le customer
       $customer->update();
       // On ajoute une nouvelle adresse
       $address = new Address();
       // On relie l'adresse au client
       $address->id_customer = (int)$customer->id;
       $address->company = $company;
       $address->alias = Tools::getValue('alias');
       $address->vat_number = Tools::getValue('tva');
       $address->firstname = $customer->firstname;
       $address->lastname = $customer->lastname;
       $address->address1 = Tools::getValue('adress1');
       $address->address2 = Tools::getValue('adress2');
       //$address->other = "infos complements";

       $address->postcode = Tools::getValue('postcode');
       $address->city = Tools::getValue('city');
       $address->id_country = Tools::getValue('id_country');
       $address->phone =  Tools::getValue('phone');

       $address->add();


   }     


public function hookAdditionalCustomerFormFields()
{

  return [
    (new FormField)
    ->setName('alias')
    ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Alias')),
        (new FormField)
        ->setName('company')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Société')),
        (new FormField)
        ->setName('tva')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Numéro de TVA')),
        (new FormField)
        ->setName('adress1')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Adresse')),
        (new FormField)
        ->setName('adress2')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Complément d\'adresse')),
        (new FormField)
        ->setName('postcode')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Code Postal')),
        (new FormField)
        ->setName('city')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Ville')),
       (new FormField)
        ->setName('id_country')
        ->setRequired(true)
        ->setType('countrySelect')
        ->setAvailableValues([
            '8' => 'France', 
            '3' => 'Belgique',
            // Ajouter autant de pays qu'on le souhaite
        ])
        ->setLabel($this->l('Pays')),

        (new FormField)
        ->setName('phone')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Téléphone')),

    ];


}
}

 

 

baba_adress_customer_form.zip

Alexandre Carette

Alexandre Carette

Salut, oui c'est possible, je t'ai fais un petit module rapidement

<?php
/**
* 2007-2020 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-2020 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 Baba_adress_customer_form extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'baba_adress_customer_form';
        $this->tab = 'administration';
        $this->version = '0.0.0';
        $this->author = 'Alexandre Carette';
        $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('baba_adress_customer_form');
        $this->description = $this->l('Allow to add adress in customer form.');

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

        return parent::install() &&
        $this->registerHook('actionObjectCustomerAddAfter') &&
        $this->registerHook('additionalCustomerFormFields');
    }

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

        return parent::uninstall() &&
        $this->unregisterHook('actionBeforeSubmitAccount') &&
        $this->unregisterHook('additionalCustomerFormFields');



    }

    /**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitBaba_adress_customer_formModule')) == 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 = 'submitBaba_adress_customer_formModule';
        $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' => 'BABA_ADRESS_CUSTOMER_FORM_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' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE', true),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL', '[email protected]'),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_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));
        }
    }

    public function hookActionObjectCustomerAddAfter(array $params)
    {

        $company = Tools::getValue('company');
      

        // On ajoute l'adresse du client à la création de l'objet customer
       // On instancie l'objet Customer qui vient de créer son compte
       $customer = new Customer((int)$params['object']->id);
       // On ajoute le nom de sa compagnie
       $customer->company = $company;
       // on update le customer
       $customer->update();
       // On ajoute une nouvelle adresse
       $address = new Address();
       // On relie l'adresse au client
       $address->id_customer = (int)$customer->id;
       $address->company = $company;
       $address->alias = Tools::getValue('alias');
       $address->vat_number = Tools::getValue('tva');
       $address->firstname = $customer->firstname;
       $address->lastname = $customer->lastname;
       $address->address1 = Tools::getValue('adress1');
       $address->address2 = Tools::getValue('adress2');
       //$address->other = "infos complements";

       $address->postcode = Tools::getValue('postcode');
       $address->city = Tools::getValue('city');
       $address->id_country = Tools::getValue('id_country');
       $address->phone =  Tools::getValue('phone');

       $address->add();


   }     


public function hookAdditionalCustomerFormFields()
{

  return [
    (new FormField)
    ->setName('alias')
    ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Alias')),
        (new FormField)
        ->setName('company')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Société')),
        (new FormField)
        ->setName('tva')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Numéro de TVA')),
        (new FormField)
        ->setName('adress1')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Adresse')),
        (new FormField)
        ->setName('adress2')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Complément d\'adresse')),
        (new FormField)
        ->setName('postcode')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Code Postal')),
        (new FormField)
        ->setName('city')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Ville')),
       (new FormField)
        ->setName('id_country')
        ->setRequired(true)
        ->setType('countrySelect')
        ->setAvailableValues([
            '8' => 'France', 
            '3' => 'Belgique',
            // Ajouter autant de pays qu'on le souhaite
        ])
        ->setLabel($this->l('Pays')),

        (new FormField)
        ->setName('phone')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Téléphone')),

    ];


}
}

 

 

Alexandre Carette

Alexandre Carette

Salut, oui c'est possible, je t'ai fais un petit module rapidement

<?php
/**
* 2007-2020 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-2020 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 Baba_adress_customer_form extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'baba_adress_customer_form';
        $this->tab = 'administration';
        $this->version = '0.0.0';
        $this->author = 'Alexandre Carette';
        $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('baba_adress_customer_form');
        $this->description = $this->l('Allow to add adress in customer form.');

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

        return parent::install() &&
        $this->registerHook('actionObjectCustomerAddAfter') &&
        $this->registerHook('additionalCustomerFormFields');
    }

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

        return parent::uninstall() &&
        $this->unregisterHook('actionBeforeSubmitAccount') &&
        $this->unregisterHook('additionalCustomerFormFields');



    }

    /**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitBaba_adress_customer_formModule')) == 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 = 'submitBaba_adress_customer_formModule';
        $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' => 'BABA_ADRESS_CUSTOMER_FORM_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' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE', true),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL', '[email protected]'),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_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));
        }
    }

    public function hookActionObjectCustomerAddAfter(array $params)
    {

        $company = Tools::getValue('company');
      

        // On ajoute l'adresse du client à la création de l'objet customer
       // On instancie l'objet Customer qui vient de créer son compte
       $customer = new Customer((int)$params['object']->id);
       // On ajoute le nom de sa compagnie
       $customer->company = $company;
       // on update le customer
       $customer->update();
       // On ajoute une nouvelle adresse
       $address = new Address();
       // On relie l'adresse au client
       $address->id_customer = (int)$customer->id;
       $address->company = $company;
       $address->alias = Tools::getValue('alias');
       $address->vat_number = Tools::getValue('tva');
       $address->firstname = $customer->firstname;
       $address->lastname = $customer->lastname;
       $address->address1 = Tools::getValue('adress1');
       $address->address2 = Tools::getValue('adress2');
       //$address->other = "infos complements";

       $address->postcode = Tools::getValue('postcode');
       $address->city = Tools::getValue('city');
       $address->id_country = Tools::getValue('id_country');
       $address->phone =  Tools::getValue('phone');

       $address->add();


   }     


public function hookAdditionalCustomerFormFields()
{

  return [
    (new FormField)
    ->setName('alias')
    ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Alias')),
        (new FormField)
        ->setName('company')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Société')),
        (new FormField)
        ->setName('tva')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Numéro de TVA')),
        (new FormField)
        ->setName('adress1')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Adresse')),
        (new FormField)
        ->setName('adress2')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Complément d\'adresse')),
        (new FormField)
        ->setName('postcode')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Code Postal')),
        (new FormField)
        ->setName('city')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Ville')),
       (new FormField)
        ->setName('id_country')
        ->setRequired(true)
        ->setType('countrySelect')
        ->setAvailableValues([
            '8' => 'France', 
            '3' => 'Belgique',
            // Ajouter autant de pays qu'on le souhaite
        ])
        ->setLabel($this->l('Pays')),

        (new FormField)
        ->setName('phone')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Téléphone')),

    ];


}
}

 

baba_adress_customer_form.zip

Alexandre Carette

Alexandre Carette

Salut, oui c'est possible, je t'ai fais un petit module rapidement

<?php
/**
* 2007-2020 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-2020 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 Baba_adress_customer_form extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'baba_adress_customer_form';
        $this->tab = 'administration';
        $this->version = '0.0.0';
        $this->author = 'Alexandre Carette';
        $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('baba_adress_customer_form');
        $this->description = $this->l('Allow to add adress in customer form.');

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

        return parent::install() &&
        $this->registerHook('actionObjectCustomerAddAfter') &&
        $this->registerHook('additionalCustomerFormFields');
    }

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

        return parent::uninstall() &&
        $this->unregisterHook('actionBeforeSubmitAccount') &&
        $this->unregisterHook('additionalCustomerFormFields');



    }

    /**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitBaba_adress_customer_formModule')) == 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 = 'submitBaba_adress_customer_formModule';
        $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' => 'BABA_ADRESS_CUSTOMER_FORM_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' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE', true),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL', '[email protected]'),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_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));
        }
    }

    public function hookActionObjectCustomerAddAfter(array $params)
    {

        $company = Tools::getValue('company');
      

        // On ajoute l'adresse du client à la création de l'objet customer
       // On instancie l'objet Customer qui vient de créer son compte
       $customer = new Customer((int)$params['object']->id);
       // On ajoute le nom de sa compagnie
       $customer->company = $company;
       // on update le customer
       $customer->update();
       // On ajoute une nouvelle adresse
       $address = new Address();
       // On relie l'adresse au client
       $address->id_customer = (int)$customer->id;
       $address->company = $company;
       $address->alias = Tools::getValue('alias');
       $address->vat_number = Tools::getValue('tva');
       $address->firstname = $customer->firstname;
       $address->lastname = $customer->lastname;
       $address->address1 = Tools::getValue('adress1');
       $address->address2 = Tools::getValue('adress2');
       //$address->other = "infos complements";

       $address->postcode = Tools::getValue('postcode');
       $address->city = Tools::getValue('city');
       $address->id_country = Tools::getValue('id_country');
       $address->phone =  Tools::getValue('phone');

       $address->add();


   }     


public function hookAdditionalCustomerFormFields()
{

  return [
    (new FormField)
    ->setName('alias')
    ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Alias')),
        (new FormField)
        ->setName('company')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Société')),
        (new FormField)
        ->setName('tva')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Numéro de TVA')),
        (new FormField)
        ->setName('adress1')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Adresse')),
        (new FormField)
        ->setName('adress2')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Complément d\'adresse')),
        (new FormField)
        ->setName('postcode')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Code Postal')),
        (new FormField)
        ->setName('city')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Ville')),
       (new FormField)
        ->setName('id_country')
        ->setRequired(true)
        ->setType('countrySelect')
        ->setAvailableValues([
            '8' => 'France', 
            '3' => 'Belgique',
            // Ajouter autant de pays qu'on le souhaite
        ])
        ->setLabel($this->l('Pays')),
         //Décommenter pour rendre obligatoire

        (new FormField)
        ->setName('phone')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Téléphone')),

        /*(new FormField)
        ->setName('justificatif_upload')
        ->setType('file')
        ->setLabel($this->l('document ID'))*/
    ];


}
}

 

baba_adress_customer_form.zip

Alexandre Carette

Alexandre Carette

Salut, oui c'est possible, je t'ai fais un petit module rapidement

<?php
/**
* 2007-2020 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-2020 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 Baba_adress_customer_form extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'baba_adress_customer_form';
        $this->tab = 'administration';
        $this->version = '0.0.0';
        $this->author = 'Alexandre Carette';
        $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('baba_adress_customer_form');
        $this->description = $this->l('Allow to add adress in customer form.');

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

        return parent::install() &&
        $this->registerHook('actionObjectCustomerAddAfter') &&
        $this->registerHook('additionalCustomerFormFields');
    }

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

        return parent::uninstall() &&
        $this->unregisterHook('actionBeforeSubmitAccount') &&
        $this->unregisterHook('additionalCustomerFormFields');



    }

    /**
     * Load the configuration form
     */
    public function getContent()
    {
        /**
         * If values have been submitted in the form, process.
         */
        if (((bool)Tools::isSubmit('submitBaba_adress_customer_formModule')) == 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 = 'submitBaba_adress_customer_formModule';
        $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' => 'BABA_ADRESS_CUSTOMER_FORM_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' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL',
                        'label' => $this->l('Email'),
                    ),
                    array(
                        'type' => 'password',
                        'name' => 'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD',
                        'label' => $this->l('Password'),
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                ),
            ),
        );
    }

    /**
     * Set values for the inputs.
     */
    protected function getConfigFormValues()
    {
        return array(
            'BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_LIVE_MODE', true),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_EMAIL', '[email protected]'),
            'BABA_ADRESS_CUSTOMER_FORM_ACCOUNT_PASSWORD' => Configuration::get('BABA_ADRESS_CUSTOMER_FORM_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));
        }
    }

    public function hookActionObjectCustomerAddAfter(array $params)
    {

        $company = Tools::getValue('company');
      

        // On ajoute l'adresse du client à la création de l'objet customer
       // On instancie l'objet Customer qui vient de créer son compte
       $customer = new Customer((int)$params['object']->id);
       // On ajoute le nom de sa compagnie
       $customer->company = $company;
       // on update le customer
       $customer->update();
       // On ajoute une nouvelle adresse
       $address = new Address();
       // On relie l'adresse au client
       $address->id_customer = (int)$customer->id;
       $address->company = $company;
       $address->alias = Tools::getValue('alias');
       $address->vat_number = Tools::getValue('tva');
       $address->firstname = $customer->firstname;
       $address->lastname = $customer->lastname;
       $address->address1 = Tools::getValue('adress1');
       $address->address2 = Tools::getValue('adress1');
       //$address->other = "infos complements";

       $address->postcode = Tools::getValue('postcode');
       $address->city = Tools::getValue('city');
       $address->id_country = Tools::getValue('id_country');
       $address->phone =  Tools::getValue('phone');

       $address->add();


   }     


public function hookAdditionalCustomerFormFields()
{

  return [
    (new FormField)
    ->setName('alias')
    ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Alias')),
        (new FormField)
        ->setName('company')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Société')),
        (new FormField)
        ->setName('tva')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Numéro de TVA')),
        (new FormField)
        ->setName('adress1')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Adresse')),
        (new FormField)
        ->setName('adress2')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Complément d\'adresse')),
        (new FormField)
        ->setName('postcode')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Code Postal')),
        (new FormField)
        ->setName('city')
        ->setType('text')
        ->setRequired(true) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Ville')),
       (new FormField)
        ->setName('id_country')
        ->setRequired(true)
        ->setType('countrySelect')
        ->setAvailableValues([
            '8' => 'France', 
            '3' => 'Belgique',
            // Ajouter autant de pays qu'on le souhaite
        ])
        ->setLabel($this->l('Pays')),
         //Décommenter pour rendre obligatoire

        (new FormField)
        ->setName('phone')
        ->setType('text')
        ->setRequired(false) //Décommenter pour rendre obligatoire
        ->setLabel($this->l('Téléphone')),

        /*(new FormField)
        ->setName('justificatif_upload')
        ->setType('file')
        ->setLabel($this->l('document ID'))*/
    ];


}
}

 

baba_adress_customer_form.zip

×
×
  • Create New...