Jump to content

1.7.6.1 Edit Extra Customer Fields in Back Office


Rhapsody

Recommended Posts

Need help modifying back office customer edit form to accommodate custom fields

I'm moving a 1.5.6.2 shop to 1.7.6.1 due to required server PHP upgrades. The existing 1.5.6.2 shop has additional text fields that were added to the customer table.  The database has been imported to a clean 1.7.6.1 install with the extra fields.  I have accomplished the following on the 1.7.6.1 install:

  • Successfully modified the classic theme to add the extra fields and saving them on New User registration
  • Successfully modified the Edit your personal information page so the fields may be updated and saved.
  • Successfully modified back office to display the extra fields when viewing a customer.

I am having problems trying to figure out how to modify the form to edit the new fields in the back office.  The approach I've taken is not optimal because  I did it with overrides and template mods.  What I would like to know if anyone can help with how this may be done using hooks.  I am not familiar with this approach but see that is the recommended approach. 

Can anyone provide tips on how to accomplish this?

 

The code below provides the field definitions in the override file. 

 

<?php
/**
* THC created from 1.7.6.1 of customer.php
* Adds custom field definitions
* spouse, yachtclub, boat, model, sailnum, phrfspin, phrfnonspin, officer 
*
**/
class Customer extends CustomerCore
{

	/** @var string spouse - THC add for spouse name */
	public 		$spouse;

	/** @var string yachtclub - THC add for YC name*/
	public 		$yachtclub;

	/** @var string boat - THC add for boat name*/
	public 		$boat;

	/** @var string model - THC add for boat model*/
	public 		$model;

	/** @var string sailnum - THC add for sail number*/
	public 		$sailnum;

	/** @var integer phrfspin - THC add for PHRF spinnaker*/
	public 		$phrfspin;

	/** @var integer phrfnonspin - THC add for PHRF non-spinnaker*/
	public 		$phrfnonspin;

	/** @var integer officer - THC add for Officer Position*/
	public 		$officer;

// this was from core with custom fields added to array
    public static $definition = array(
        'table' => 'customer',
        'primary' => 'id_customer',
        'fields' => array(
            'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_post' => false),
            'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 255),
            'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 255),
            'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 255),
            'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 255),
            'last_passwd_gen' => array('type' => self::TYPE_STRING, 'copy_post' => false),
            'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
            'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate'),
            'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
            'newsletter_date_add' => array('type' => self::TYPE_DATE, 'copy_post' => false),
            'ip_registration_newsletter' => array('type' => self::TYPE_STRING, 'copy_post' => false),
            'optin' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
            'website' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl'),
            'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
            'siret' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
            'ape' => array('type' => self::TYPE_STRING, 'validate' => 'isApe'),
            'outstanding_allow_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'copy_post' => false),
            'show_public_prices' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
            'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
            'max_payment_days' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
            'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
            'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
            'note' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'size' => 65000, 'copy_post' => false),
            'is_guest' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
            'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
            'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
            'id_default_group' => array('type' => self::TYPE_INT, 'copy_post' => false),
            'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', '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),
            'reset_password_token' => array('type' => self::TYPE_STRING, 'validate' => 'isSha1', 'size' => 40, 'copy_post' => false),
            'reset_password_validity' => array('type' => self::TYPE_DATE, 'validate' => 'isDateOrNull', 'copy_post' => false),
			'spouse' =>					array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
			'yachtclub' =>					array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
			'boat' =>						array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
			'model' =>						array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
			'sailnum' =>					array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
			'phrfspin' => 					array('type' => self::TYPE_INT, 'validate' => 'isInt'),
			'phrfnonspin' => 				array('type' => self::TYPE_INT, 'validate' => 'isInt'),
			'officer' =>    				array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
        ),
    );


  
}

 

Link to comment
Share on other sites

  • 10 months later...

Hello!

Just add the fields you are interested in from your form

If you have a field in the form called status_customer, create only that one as public $status_customer.

class Customer extends CustomerCore
{

	public $status_customer;

Check the changes in public static $definition  or copy it from the original and add only the line you are interested in:

public static $definition = array(
        'table' => 'customer',
        'primary' => 'id_customer',
        'fields' => array(
            'status_customer' => array('type' => self::TYPE_STRING, 'required' => true),

For example column status_customer has to be created in ps_customer.

You have to do an override of classes/form/CustomerFormatter.php and search for public function getFormat()

and add, for example

$format['status_customer'] = (new FormField())
            ->setName('status_customer')
            ->setType('radio-buttons')
            ->setLabel(
                $this->translator->trans(
                    'Type of customer',
                    [],
                    'Shop.Forms.Labels'
                )
            )
            ->addAvailableValue('professional', 'Professional')
            ->addAvailableValue('private', 'Private')
            ->setRequired(true);

more info: http://prestacraft.com/adding-new-fields-to-the-registration-form-in-prestashop-1-7/#

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