Jump to content

Edit History

sococa

sococa

Bonjour tout le monde,

J'ai créé un module pour ajouter des champs au formulaire d'inscription (customerform) en utilisant le hook additionalCustomerFormFields.
Le truc, c'est que j'aimerais que les nouveaux champs apparaissent au milieu du customerform, après le champ siret. Pas à la fin.
J'ai vu que c'était possible en créant un hook et en appelant ce hook directement dans le customerForm, mais cela me renvoi systématiquement l'erreur " ( ! ) Warning: Array to string conversion in /var/www/prestashop/classes/Hook.php on line 936".
Voici le code en question
 

public function hookDisplayTest($params)
    {
        $countries = Country::getCountries($this->context->language->id, true);

        $additionalFields = [];

        $selectedDefaultCountry = $this->context->country->id;
        $idCountryField = (new FormField)
            ->setName('id_country')
            ->setType('select')
            ->setLabel($this->l('Pays'))
            ->setRequired(true);
        
        $additionalFields[] = $idCountryField;
        foreach ($countries as $country) {
            $idCountryField->addAvailableValue(
                $country['id_country'],
                $country['name']
            );
        }
        
        $additionalFields[] = (new FormField)
            ->setName('vat_number')
            ->setType('text')
            ->setLabel($this->l('N° TVA'))
            ->setMaxLength(12)
            ->setRequired(true)
            ->addConstraint('isVatNumber');

        $additionalFields[] = (new FormField)
            ->setName('activity')
            ->setType('select')
            ->setLabel($this->l('Activité'))
            ->setRequired(true)
            ->setAvailableValues([
                'Commerce' => $this->l('Commerce'),
                'Industrie' => $this->l('Industrie'),
                'Services' => $this->l('Services'),
                'Autre' => $this->l('Autre'),
            ]);
            
        $additionalFields[] = (new FormField)
            ->setName('phone')
            ->setType('tel')
            ->setLabel($this->l('Téléphone'))
            ->setRequired(true)
            ->addConstraint('isPhoneNumber');


        
        $additionalFields[] = (new FormField)
            ->setName('address1')
            ->setType('text')
            ->setLabel($this->l('Adresse'))
            ->setRequired(true)
            ->addConstraint('isAddress');

        $additionalFields[] = (new FormField)
            ->setName('address2')
            ->setType('text')
            ->setLabel($this->l('Complément d\'adresse'))
            ->addConstraint('isAddress');


        $additionalFields[] = (new FormField)
            ->setName('postcode')
            ->setType('text')
            ->setLabel($this->l('Code postal'))
            ->setRequired(true)
            ->addConstraint('isPostCode');

        $additionalFields[] = (new FormField)
            ->setName('city')
            ->setType('text')
            ->setLabel($this->l('Ville'))
            ->setRequired(true)
            ->addConstraint('isCityName');

        return $additionalFields;
    }

<form action="{block name='customer_form_actionurl'}{$action}{/block}" id="customer-form" class="js-customer-form" method="post">
  <div>
    {block "form_fields"}
      {foreach from=$formFields item="field"}
        {block "form_field"}
          {if $field.type === "password"}
            <div class="field-password-policy">
              {form_field field=$field}
            </div>
          {else}
            {form_field field=$field}
            {if $field.name == "siret"}
              <p><a href="/nous-contacter" target="_blank">Pas encore de SIRET? Contactez-nous</a></p>
              {hook h='displayTest'}
            {/if}
          {/if}
        {/block}

      {/foreach}

      {$hook_create_account_form nofilter}
    {/block}
    
  </div>

J'ai aussi essayé avec le hook actionCustomerFormBuilderModifier, mais n'ai pas eu plus de résultats. Il ne se passait rien.

j'espère que quelqu'un pourra m'aider.

Merci d'avance :) 

ps_customregistrationfields.zip

sococa

sococa

Bonjour tout le monde,

J'ai créé un module pour ajouter des champs au formulaire d'inscription (customerform) en utilisant le hook additionalCustomerFormFields.
Le truc, c'est que j'aimerais que les nouveaux champs apparaissent au milieu du customerform, après le champ siret. Pas à la fin.
J'ai vu que c'était possible en créant un hook et en appelant ce hook directement dans le customerForm, mais cela me renvoi systématiquement l'erreur " ( ! ) Warning: Array to string conversion in /var/www/prestashop/classes/Hook.php on line 936".
Voici le code en question
 

public function hookDisplayTest($params)
    {
        $countries = Country::getCountries($this->context->language->id, true);

        $additionalFields = [];

        $selectedDefaultCountry = $this->context->country->id;
        $idCountryField = (new FormField)
            ->setName('id_country')
            ->setType('select')
            ->setLabel($this->l('Pays'))
            ->setRequired(true);
        
        $additionalFields[] = $idCountryField;
        foreach ($countries as $country) {
            $idCountryField->addAvailableValue(
                $country['id_country'],
                $country['name']
            );
        }
        
        $additionalFields[] = (new FormField)
            ->setName('vat_number')
            ->setType('text')
            ->setLabel($this->l('N° TVA'))
            ->setMaxLength(12)
            ->setRequired(true)
            ->addConstraint('isVatNumber');

        $additionalFields[] = (new FormField)
            ->setName('activity')
            ->setType('select')
            ->setLabel($this->l('Activité'))
            ->setRequired(true)
            ->setAvailableValues([
                'Commerce' => $this->l('Commerce'),
                'Industrie' => $this->l('Industrie'),
                'Services' => $this->l('Services'),
                'Autre' => $this->l('Autre'),
            ]);
            
        $additionalFields[] = (new FormField)
            ->setName('phone')
            ->setType('tel')
            ->setLabel($this->l('Téléphone'))
            ->setRequired(true)
            ->addConstraint('isPhoneNumber');


        
        $additionalFields[] = (new FormField)
            ->setName('address1')
            ->setType('text')
            ->setLabel($this->l('Adresse'))
            ->setRequired(true)
            ->addConstraint('isAddress');

        $additionalFields[] = (new FormField)
            ->setName('address2')
            ->setType('text')
            ->setLabel($this->l('Complément d\'adresse'))
            ->addConstraint('isAddress');


        $additionalFields[] = (new FormField)
            ->setName('postcode')
            ->setType('text')
            ->setLabel($this->l('Code postal'))
            ->setRequired(true)
            ->addConstraint('isPostCode');

        $additionalFields[] = (new FormField)
            ->setName('city')
            ->setType('text')
            ->setLabel($this->l('Ville'))
            ->setRequired(true)
            ->addConstraint('isCityName');

        return $additionalFields;
    }

<form action="{block name='customer_form_actionurl'}{$action}{/block}" id="customer-form" class="js-customer-form" method="post">
  <div>
    {block "form_fields"}
      {foreach from=$formFields item="field"}
        {block "form_field"}
          {if $field.type === "password"}
            <div class="field-password-policy">
              {form_field field=$field}
            </div>
          {else}
            {form_field field=$field}
            {if $field.name == "siret"}
              <p><a href="/nous-contacter" target="_blank">Pas encore de SIRET? Contactez-nous</a></p>
              {hook h='displayTest'}
            {/if}
          {/if}
        {/block}

      {/foreach}

      {$hook_create_account_form nofilter}
    {/block}
    
  </div>

J'ai aussi essayé avec le hook actionCustomerFormBuilderModifier, mais n'ai pas eu plus de résultats. Il ne se passait rien.

j'espère que quelqu'un pourra m'aider.

Merci d'avance :) 

ps_customregistrationfields.zip

sococa

sococa

Bonjour tout le monde,

J'ai créé un module pour ajouter des champs au formulaire d'inscription (customerform) en utilisant le hook additionalCustomerFormFields.
Le truc, c'est que j'aimerais que les nouveaux champs apparaissent au milieu du customerform, après le champ siret. Pas à la fin.
J'ai vu que c'était possible en créant un hook et en appelant ce hook directement dans le customerForm, mais cela me renvoi systématiquement l'erreur " ( ! ) Warning: Array to string conversion in /var/www/prestashop/classes/Hook.php on line 936".
Voici le code en question
 

public function hookDisplayTest($params)
    {
        $countries = Country::getCountries($this->context->language->id, true);

        $additionalFields = [];

        $selectedDefaultCountry = $this->context->country->id;
        $idCountryField = (new FormField)
            ->setName('id_country')
            ->setType('select')
            ->setLabel($this->l('Pays'))
            ->setRequired(true);
        // ->addConstraint('isCountryName')
        
        $additionalFields[] = $idCountryField;
        foreach ($countries as $country) {
            $idCountryField->addAvailableValue(
                $country['id_country'],
                $country['name']
            );
        }
        
        $additionalFields[] = (new FormField)
            ->setName('vat_number')
            ->setType('text')
            ->setLabel($this->l('N° TVA'))
            ->setMaxLength(12)
            ->setRequired(true)
            ->addConstraint('isVatNumber');

        $additionalFields[] = (new FormField)
            ->setName('activity')
            ->setType('select')
            ->setLabel($this->l('Activité'))
            ->setRequired(true)
            ->setAvailableValues([
                'Commerce' => $this->l('Commerce'),
                'Industrie' => $this->l('Industrie'),
                'Services' => $this->l('Services'),
                'Autre' => $this->l('Autre'),
            ]);
            
        $additionalFields[] = (new FormField)
            ->setName('phone')
            ->setType('tel')
            ->setLabel($this->l('Téléphone'))
            ->setRequired(true)
            ->addConstraint('isPhoneNumber');


        
        $additionalFields[] = (new FormField)
            ->setName('address1')
            ->setType('text')
            ->setLabel($this->l('Adresse'))
            ->setRequired(true)
            ->addConstraint('isAddress');

        $additionalFields[] = (new FormField)
            ->setName('address2')
            ->setType('text')
            ->setLabel($this->l('Complément d\'adresse'))
            ->addConstraint('isAddress');


        $additionalFields[] = (new FormField)
            ->setName('postcode')
            ->setType('text')
            ->setLabel($this->l('Code postal'))
            ->setRequired(true)
            ->addConstraint('isPostCode');

        $additionalFields[] = (new FormField)
            ->setName('city')
            ->setType('text')
            ->setLabel($this->l('Ville'))
            ->setRequired(true)
            ->addConstraint('isCityName');

        /*$additionalFields[] = (new FormField)
            ->setName('other_activity')
            ->setType('text')
            ->setLabel($this->l('Préciser votre activité'))
            ->setRequired(false)
            ->setAvailableValues([]);*/

        return $additionalFields;
    }

<form action="{block name='customer_form_actionurl'}{$action}{/block}" id="customer-form" class="js-customer-form" method="post">
  <div>
    {block "form_fields"}
      {foreach from=$formFields item="field"}
        {block "form_field"}
          {if $field.type === "password"}
            <div class="field-password-policy">
              {form_field field=$field}
            </div>
          {else}
            {form_field field=$field}
            {if $field.name == "siret"}
              <p><a href="/nous-contacter" target="_blank">Pas encore de SIRET? Contactez-nous</a></p>
              {hook h='displayTest'}
            {/if}
          {/if}
        {/block}

      {/foreach}

      {$hook_create_account_form nofilter}
    {/block}
    
  </div>

J'ai aussi essayé avec le hook actionCustomerFormBuilderModifier, mais n'ai pas eu plus de résultats. Il ne se passait rien.

j'espère que quelqu'un pourra m'aider.

Merci d'avance :) 

ps_customregistrationfields.zip

×
×
  • Create New...