Jump to content

Add custom field in PrestaShop 1.7


webmonger

Recommended Posts

I am adding custom field to address by overiding Address class:

<?php 
class Address extends AddressCore
{
    public $extrafield;
 
    public function __construct($id_address = null, $id_lang = null)
    {
        self::$definition['fields']['extrafield'] = array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64);
        parent::__construct($id_address, $id_lang);
    }
}

Also I have modified the template to add the new input field.

 

This scenario is working in PrestaShop 1.6, new input is saved in database. But in PrestaShop 1.7, the new input is not saved in database. Am I missing something here ?

 

Thanks

Link to comment
Share on other sites

I think i found why in PrestaShop 1.7 the extrafield is not auto-inserted to database as in PrestaShop 1.6.

 

In AddressController, postProcess:

$this->address_form->fillWith(Tools::getAllValues());

The Tools::getAllValues() already contains all value submitted. But the address_form's fillWith only fill the field from the country's format address.

 

In the end, it would be great if actionAddressSave is added to core :)

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

  • 1 month later...

I am adding custom field to address by overiding Address class:

<?php 
class Address extends AddressCore
{
    public $extrafield;
 
    public function __construct($id_address = null, $id_lang = null)
    {
        self::$definition['fields']['extrafield'] = array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64);
        parent::__construct($id_address, $id_lang);
    }
}

Also I have modified the template to add the new input field.

 

This scenario is working in PrestaShop 1.6, new input is saved in database. But in PrestaShop 1.7, the new input is not saved in database. Am I missing something here ?

 

Thanks

 

How does you modified your template for present your field?

Link to comment
Share on other sites

  • 2 years later...

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