Jump to content

Personnalisé le formulaire de création d'un compte


Recommended Posts

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

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

  • 2 months later...

Bonjour, 

Je m'intéresse à votre module, mais le télécharger n'est plus actif.

J'ai essayé de créer le module à la main en faisant un répertoire Baba_adress_customer_form avec dedans un fichier nommé : baba_adress_customer_form.php qui contient le code indiqué.

Mais sans succès : module non valide.

Pourriez-vous m'aiguiller svp ?

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...
On 12/31/2020 at 1:23 PM, Alexandre Carette said:

cdt,

Capture.JPG

SUPER, exactement ce que je recherchais, merci ! 

Avez-vous la documentation s'il vous plait car elle ne s'affiche pas lorsque l'on clique sur le lien en BO ?

Comment faire pour que le module s'affiche au dessus du bloc d'acceptation des conditions de ventes et de confidentialité ? 

Concernant le sélecteur de pays, comment je pourrais forcer l'affichage de France par défaut s'il vous plait ?

 

Merci d'avance

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

10 hours ago, INTJP said:

SUPER, exactement ce que je recherchais, merci ! 

Avez-vous la documentation s'il vous plait car elle ne s'affiche pas lorsque l'on clique sur le lien en BO ?

Comment faire pour que le module s'affiche au dessus du bloc d'acceptation des conditions de ventes et de confidentialité ? 

Concernant le sélecteur de pays, comment je pourrais forcer l'affichage de France par défaut s'il vous plait ?

 

Merci d'avance

 

Je me réponds à moi-même si jamais cela intéresse quelqu'un : 

A partir du BO de Prestashop :

Pour modifier l'affichage -> Design > positions > sélectionner le bon module "baba_adress_customer_form" > cocher "afficher les points d'accroches invisibles" et déplacer le module concerné ou vous voulez.

Pour forcer l'affichage du pays : modifier directement le fichier php > /modules/baba_adress_customer_form/baba_adress_customer_form.php

 

(new FormField)
        ->setName('id_country')
        ->setRequired(true)
        ->setType('countrySelect')
        ->setAvailableValues([
            '8' => 'France', 
            // Ajouter autant de pays qu'on le souhaite
        ])
        ->setValue('8') // le code du pays que vous souhaitez afficher par défaut
        ->setLabel($this->l('Pays')),
         //Décommenter pour rendre obligatoire

 

Link to comment
Share on other sites

On 12/31/2020 at 1:23 PM, Alexandre Carette said:

cdt,

Capture.JPG

Bonjour,

Encore une fois, merci pour ce super module !

Je me permets de revenir vers vous car je ne comprends pas pourquoi les informations du formulaire de création de compte se retrouvent bien dans :

site.com/addresses

349550179_Capturedecran2023-04-04a12_22_23.png.ed40662fe6175162ead3cf584a41bf3c.png

mais pas dans 

site.com/identity

1342836430_Capturedecran2023-04-04a12_23_01.thumb.png.81a752776d06f07daf6758ecaa6d1a76.png

 

Comment faire pour qu'elles apparaissent également sur la page identity ?

Merci d'avance.

Link to comment
Share on other sites

  • 1 year later...
  • 8 months later...

Bonsoir, à tous

j'ai testé mais malheureusement l'adresse du client, le Pays, le code postal  ne s'enregistre dans la fiche client

Merci pour l'aide

Suis en Presta 1.7.8.11  

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