Cronogato Posted September 28, 2021 Share Posted September 28, 2021 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 More sharing options...
Janett Posted September 28, 2021 Share Posted September 28, 2021 (edited) 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 September 28, 2021 by Janett (see edit history) 1 Link to comment Share on other sites More sharing options...
Cronogato Posted September 28, 2021 Author Share Posted September 28, 2021 That doesn't seems to work either 😕 Maybe im not inserting the public function hookActionCustomerAccountAdd() in the right place? Link to comment Share on other sites More sharing options...
Janett Posted September 28, 2021 Share Posted September 28, 2021 After adding it into module or module override, you need to register it in PrestaShop. See https://devdocs.prestashop.com/1.7/modules/concepts/hooks/ 1 Link to comment Share on other sites More sharing options...
Cronogato Posted September 28, 2021 Author Share Posted September 28, 2021 First thanks for taking the time to help @Janett. I searched for and used an already registered hook and called it from the template with {hook h='additionalCustomerFormFields'}, but it still doesn't works, the DB table doesn't show new lines with the value. Link to comment Share on other sites More sharing options...
ps8modules Posted September 29, 2021 Share Posted September 29, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now