Jump to content

Insert value into DB table from registration form


Cronogato

Recommended Posts

Hi,
I bought a module for an specific tax mode for my country and I need to ask the customer if he is into this specific mode and then manually activate the user by the module configuration page.
The method the module is using is, if I check the user in the module configuration page, it adds the user id to a DB table.

I want to do this by the user itself when he register by the registration form, and I've made this code in the Customer.php override that comes with the module.

public function hookActionCustomerAccountAdd() {
	if (Tools::isSubmit('chkRecargoEquivalencia')) {
    	if (Tools::isSubmit('chkRecargoEquivalencia') == 1) {
			DB::getInstance()->insert('ps_esp_recargo_equivalencia_prueba', array('id_customer' => (int)$this->id,));
		}
	}
}

And this in the .tpl where the registration form is:

<span class="custom-checkbox">
	<input id="chkRecargoEquivalencia" name="chkRecargoEquivalencia" type="checkbox" value="1">
    <span><i class="material-icons checkbox-checked"></i></span>
    <label>¿Aplicar recargo de equivalencia al IVA?</label>
</span>

But it isn't working.

Any help with this would be very appreciated.

Thanks!

Link to comment
Share on other sites

Try

    /**
     * @param array{cookie: Cookie, cart: Cart, altern: int, newCustomer: Customer} $params
     * @see CustomerPersisterCore::create
     */
    public function hookActionCustomerAccountAdd(array $params)
    {
        if (Tools::getValue('chkRecargoEquivalencia') === '1' && Validate::isLoadedObject($params['newCustomer'])) {
            Db::getInstance()->insert(
                'esp_recargo_equivalencia_prueba',
                [
                    'id_customer' => (int) $params['newCustomer']->id,
                ]
            );
        }
    }

 

Edited by Janett (see edit history)
  • Like 1
Link to comment
Share on other sites

public function insert($table, $data, $null_values = false, $use_cache = true, $type = Db::INSERT, $add_prefix = true)

If esp_recargo_equivalencia_prueba is the full name of the database table, including the prefix, you must change the parameter $ add_prefix = false.
Or don't give a table prefix.

if (Tools::getValue('chkRecargoEquivalencia') === '1' && Validate::isLoadedObject($params['newCustomer'])) {
            Db::getInstance()->insert(
                'recargo_equivalencia_prueba',
                [
                    'id_customer' => (int) $params['newCustomer']->id,
                ]
            );
        }
    

or

if (Tools::getValue('chkRecargoEquivalencia') === '1' && Validate::isLoadedObject($params['newCustomer'])) {
            Db::getInstance()->insert(
                'esp_recargo_equivalencia_prueba', /* table */
                [
                    'id_customer' => (int) $params['newCustomer']->id, /* $data */
                ],
				false, /* $null_values */
				true, /* $use_cache */
				Db::INSERT_IGNORE, /* $type INSERT, INSERT_IGNORE, REPLACE*/
				false /* $add_prefix */
            );
        }
    

 

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