Jump to content

Rajouter des champs dans les adresses clients


Recommended Posts

Bonjour,

 

Je suis sous presta 1.6.1.4 et je souhaite rajouter des champs dans les adresses.

 

Voici la liste des champs que je souhaite rajouter :

  • Boite postale
  • Service
  • lieu-dit
  • fax
  • adresse ligne 3

 

J'ai donc commencé par créer les champs dans la base de données, dans la table address (en fin de table).

 

Puis niveau code, par un override de la classe Address (override/Address.php) :

class Address extends AddressCore
{
	public $boite_postale;
	public $service;
	public $lieu_dit;
	public $fax;
	public $address3;
 
 
    public static $definition = array(
        'table' => 'address',
        'primary' => 'id_address',
        'fields' => array(
            'id_customer' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_manufacturer' =>    array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_supplier' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_warehouse' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_country' =>        array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
            'id_state' =>            array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
            'alias' =>                array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
            'company' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
            'lastname' =>            array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
            'firstname' =>            array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
            'vat_number' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
            'address1' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128),
            'address2' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
            'postcode' =>            array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12),
            'city' =>                array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64),
            'other' =>                array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300),
            'phone' =>                array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
            'phone_mobile' =>        array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
            'dni' =>                array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16),
            'deleted' =>            array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
            'date_add' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
            'date_upd' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
			'boite_postale' =>            array('type' => self::TYPE_DATE, 'validate' => 'isGenericName', 'copy_post' => false),
			'service' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
			'lieu_dit' =>               array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
			'fax' =>               array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 32),
			'address3' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
        ),
    );

Puis dans le tpl du front de mon theme (le theme classique defaukt-bootstrap)

 

Je vais pas tout mettre alors voici un exemple pour le champ "address3"

{if $field_name eq 'address3'}
	<div class="required form-group">
		<label for="address3">{l s='Address (Line 3)'}{if isset($required_fields) && in_array($field_name, $required_fields)} <sup>*</sup>{/if}</label>
		<input class="validate form-control" data-validate="{$address_validation.$field_name.validate}" type="text" id="address3" name="address3" value="{if isset($smarty.post.address3)}{$smarty.post.address3}{else}{if isset($address->address3)}{$address->address3|escape:'html':'UTF-8'}{/if}{/if}" />
	</div>
{/if}

Et enfin un override du controller AdminAddressesController (override/controllers/admin/AdminAddressesController.php

 

J'ai simplement refait la fonction renderForm() en rajoutant mes champs et terminé par un 

 

return AdminController::renderForm();

 

 

 

 

Au final, ça ne fonctionne pas, je ne vois pas du tout les champs, dans le front ni dans backend... J'ai loupé une étape qqch ??

 

Merci grandement de votre aide.

Edited by Regaton (see edit history)

Share this post


Link to post
Share on other sites

Ok j'ai trouvé... Tout le code est bon c'est juste qu'il fallait appeler les champs dans Localisation/Pays/France et modifier le format adresse....

 

2 jours sur cette */%?$*£! de problème !!!!

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More