vermich Posted June 27, 2013 Share Posted June 27, 2013 (edited) Bonjours à tous, j'ai un module qui au moment de l'inscription place l'utilisateur dans un groupe en fonction du code qu'il a entré. Je sollicite votre aide car je souhaiterai que ses adresses de livraison et de facturation soit celles que j'ai associé au groupe. voici ma fonction, mais je ne trouve pas la fonction d'update d'addresses public function hookcreateAccount($params) { //this is the customer object $customer = $params['newCustomer']; $codece = Tools::getValue('codece'); // code compagny from registration $sql = "SELECT id_group FROM ps_group_lang WHERE code = '$codece'"; // $id_default_group = (int)Db::getInstance()->getValue($sql); $groupsToAdd=array(); array_push($groupsToAdd,$id_default_group); $customer->updateGroup($groupsToAdd); $this->setDefaultGroupId($customer->id,$id_default_group); $sql = "SELECT adress1 FROM ps_group_lang WHERE code = '$codece'"; $address1 = (int)Db::getInstance()->getValue($sql); $sql = "SELECT adress2 FROM ps_group_lang WHERE code = '$codece'"; $address2 = (int)Db::getInstance()->getValue($sql); $sql = "SELECT postcode FROM ps_group_lang WHERE code = '$codece'"; $postcode = (int)Db::getInstance()->getValue($sql); $sql = "SELECT city FROM ps_group_lang WHERE code = '$codece'"; $city = (int)Db::getInstance()->getValue($sql); } Edited July 8, 2013 by vermich (see edit history) Link to comment Share on other sites More sharing options...
vermich Posted June 28, 2013 Author Share Posted June 28, 2013 (edited) Alors j'ai tenté de trouvé comment l'adresse était enregistré dans addresscontroleur.php mais je ne trouve pas. j'ai donc essayé de le faire "à la main" avec un update mais rien ne semble se passer : $address = new Address(); $address->id_customer = (int)$this->context->customer->id; $sql = "SELECT adress1 FROM ps_group_lang WHERE code = '$codece'"; $address1 = Db::getInstance()->getValue($sql); $address->address1 = $address1; $sql = "SELECT adress2 FROM ps_group_lang WHERE code = '$codece'"; $address2 = Db::getInstance()->getValue($sql); $address->address2 = $address2; $sql = "SELECT postcode FROM ps_group_lang WHERE code = '$codece'"; $postcode = Db::getInstance()->getValue($sql); $address->postcode = $postcode; $sql = "SELECT city FROM ps_group_lang WHERE code = '$codece'"; $city = Db::getInstance()->getValue($sql); $address->city = $city; Db::getInstance()->update('ps_address', array( 'address1' => $address1, 'address2' => $address2, 'postcode' => $postcode, 'city' => $city )); Edited June 28, 2013 by vermich (see edit history) Link to comment Share on other sites More sharing options...
vermich Posted July 1, 2013 Author Share Posted July 1, 2013 bon j'ai essayé de refaire au propre et voir ou ça bloqué. voici ma fonction [/size] public function setDefaultAddress() { $sql = "SELECT adress1 FROM ps_group_lang WHERE code = '$codece'"; $address1 = Db::getInstance()->getValue($sql); $sql = "SELECT adress2 FROM ps_group_lang WHERE code = '$codece'"; $address2 = Db::getInstance()->getValue($sql); $sql = "SELECT postcode FROM ps_group_lang WHERE code = '$codece'"; $postcode = Db::getInstance()->getValue($sql); $sql = "SELECT city FROM ps_group_lang WHERE code = '$codece'"; $city = Db::getInstance()->getValue($sql); echo 'blablabla'; Db::getInstance()->update('address', array( 'address1' => $address1, 'address2' => $address2, 'postcode' => $postcode, 'city' => $city, ), '`id_customer` = '.(int)$customer_id); } Je l'appel ensuite avec $this->setDefaultAddress(); mais rien ne semble se passer, même mon echo n'affiche rien. Link to comment Share on other sites More sharing options...
vermich Posted July 2, 2013 Author Share Posted July 2, 2013 (edited) Si ça peut aider quelqu'un voila la finalité. J'imagine que ça ne doit pas être la façon le plus propre ou sécurisé donc si d'autres ont des conseils de modification je pendrais avec plaisir. Donc dans mon module j'ai une fonction public function setDefaultAddress($address1,$address2,$postcode,$city,$customer_id) { print $address1; Db::getInstance()->update('address', array( 'address1' => $address1, 'address2' => $address2, 'postcode' => $postcode, 'city' => $city, ), '`id_customer` = '.(int)$customer_id); } qui est appelée par une autre fonction attachée au Hook de fin de création de compte: public function hookcreateAccount($params) { //this is the customer object $customer = $params['newCustomer']; $codece = Tools::getValue('codece'); // code compagny from registration unset($sql); $sql = "SELECT address1 FROM ps_group_lang WHERE code = '$codece'"; $address1 = Db::getInstance()->getValue($sql); unset($sql); $sql = "SELECT address2 FROM ps_group_lang WHERE code = '$codece'"; $address2 = Db::getInstance()->getValue($sql); unset($sql); $sql = "SELECT postcode FROM ps_group_lang WHERE code = '$codece'"; $postcode = Db::getInstance()->getValue($sql); unset($sql); $sql = "SELECT city FROM ps_group_lang WHERE code = '$codece'"; $city = Db::getInstance()->getValue($sql); unset($sql); $this->setDefaultAddress($address1,$address2,$postcode,$city,$customer->id); } Edited July 2, 2013 by vermich (see edit history) 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