Jump to content

Edit History

elburgl69

elburgl69

Implemention with a Hooks:

1. In your Install method, add the collumn to the database. Something like:

public function install()
    {
        if (!parent::install() || !$this->installDB()) {
            return false;
        }
        
        return $this->registerHook('actionCustomerAccountAdd');
    }
    public function installDB()
    {
        $res = (bool) Db::getInstance()->execute('
            UPDATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'customers` (
                ...
            );
        ');
        // any other db operations...
        return $res;
    }

2. Implement the add Hook method like:

public function hookActionCustomerAccountAdd($params)
    {
        // YOur code
    }

3. Think about if update customer  hooks are necessary and implement those if required

4. Implement the hooks used to display the information in the front / back-end and use / cast you MyCustomer class to get the customer. Get the field value for my custom field indeed with someting like  $mycustom = Tools::getValue('mycustom'. Remember to sanitize.

5. Implement an Uninstall method to remove the hook and undo the database changes.

 

An alternative approach would be create a new table for your extra collumn(s) with id_cusomer as key. You then have a one-to-one relation. Extend the customer model like above but now to include you table information. This approach does not change the core database tables.

Rg,

Leo

 

 

 

elburgl69

elburgl69

Implemention with a Hooks:

1. In your Install method, add the collumn to the database. Something like:

public function install()
    {
        if (!parent::install() || !$this->installDB()) {
            return false;
        }
        
        return $this->registerHook('actionCustomerAccountAdd');
    }
    public function installDB()
    {
        $res = (bool) Db::getInstance()->execute('
            UPDATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'customers` (
                ...
            );
        ');
        // any other db operations...
        return $res;
    }

2. Implement the add Hook method like:

public function hookActionCustomerAccountAdd($params)
    {
        // YOur code
    }

3. Think about if update customer  hooks are necessary and implement those if require

4. Implement the hooks used to display the information in the front / back-end and use / cast you MyCustomer class to get the customer. Get the field value for my custom field indeed with someting like  $mycustom = Tools::getValue('mycustom'. Remember to sanitize.

5. Implement an Uninstall method to remove the hook and undo the database changes.

 

An alternative approach would be create a new table for your extra collumn(s) with id_cusomer as key. You then have a one-to-one relation. Extend the customer model like above but now to include you table information. This approach does not change the core database tables.

Rg,

Leo

 

 

 

×
×
  • Create New...