BeRoots Posted August 25, 2016 Share Posted August 25, 2016 (edited) Bonjour à tous J'ai un problème avec la methode update() de Db. Je n'est aucune modification de ma table celle-ci Je souhaite pourtant faire au plus propre comme expliquer sur https://www.prestashop.com/blog/fr/les-bonnes-pratiques-de-la-classe-db-sur-prestashop-1-5/ (notez que je suis sous 1.6) Voici ma méthode qui ne passe pas: <?php private function setModulePositionIntoHookDisplayTop() { //gets the position for this module into the displayTop hook $sql = "SELECT `position` FROM `ps_hook_module` WHERE `id_module` = 27 AND `id_hook` = 15;"; $module_position = Db::getInstance()->executeS($sql, $array = true, $use_cache = false); //gets the id for this module into the displayTop hook $sql = "SELECT `id_module` FROM `ps_module` WHERE `name` = '" . $this->name . "';"; $id_module = Db::getInstance()->executeS($sql, $array = true, $use_cache = false); //gets rows for the displayTop hook where position is upper to the future position of this module $sql = "SELECT * FROM `ps_hook_module` WHERE" . "`position` >= (SELECT `position` FROM `ps_hook_module` WHERE `id_module` = 27 AND `id_hook` = 15)" . " AND `id_hook` = 15" . " AND `id_module` NOT IN (SELECT `id_module` FROM `ps_module` WHERE `name` = '" . $this->name . "');"; $result = Db::getInstance()->executeS($sql, $array = true, $use_cache = false); //update position of other module then position is upper or equal to this module position foreach ($result as $value) { $p = $value['position'] + 1; $data = array('position' => $p); $where = 'id_module = '.$value['id_module'].' AND id_hook = 15'; Db::getInstance()->update('ps_hook_module', $data, $where); } //finally update the position of this module $data = array('position' => $module_position); $where_module = 'id_module = '.$id_module.' AND id_hook = 15'; Db::getInstance()->update('ps_hook_module', $data, $where_module); return true; } ?> Si quelqu'un à une idée sur le pourquoi je n'arrive pas à faire fonctionner cette methode qui est appelée en fin de methode install() de mon module Merci d'avance Edited August 25, 2016 by BeRoots (see edit history) Link to comment Share on other sites More sharing options...
Mediacom87 Posted August 25, 2016 Share Posted August 25, 2016 Bonjour, peut être que vous devriez surtout travailler avec les fonctions existante des Classes PrestaShop comme par exemple dans la classe Module avec getPosition() Link to comment Share on other sites More sharing options...
BeRoots Posted August 26, 2016 Author Share Posted August 26, 2016 Oui. Enfin pour le moment je souhaiterai comprendre comment utiliser la méthode update et surtout pourquoi elle ne fonctionne pas ici alors que si je remplace par des execute("UPDATE ...") j'ai bien modification de la table Link to comment Share on other sites More sharing options...
BeRoots Posted August 26, 2016 Author Share Posted August 26, 2016 Les points sont là pour la concaténation de chaine $str = 'une chaine' . 'concaténée'; Sinon Merci pour ton aide mais cela ne résout pas le problème. Ceci ne fonctionne toujours pas: <?php private function setModulePositionIntoHookDisplayTop() { //gets the future position for this module into the displayTop hook $sql = "SELECT `position` FROM `ps_hook_module` WHERE `id_module` = 27 AND `id_hook` = 15;"; $module_position = Db::getInstance()->getValue($sql, $use_cache = false); //gets the id for this module into the displayTop hook $sql = "SELECT `id_module` FROM `ps_module` WHERE `name` = '" . $this->name . "';"; $id_module = Db::getInstance()->getValue($sql, $use_cache = false); //gets rows for the displayTop hook where position is upper to the future position of this module $sql = "SELECT * FROM `ps_hook_module` WHERE" . " `position` >= (SELECT `position` FROM `ps_hook_module` WHERE `id_module` = 27 AND `id_hook` = 15)" . " AND `id_hook` = 15" . " AND `id_module` NOT IN (SELECT `id_module` FROM `ps_module` WHERE `name` = '" . $this->name . "');"; $result = Db::getInstance()->executeS($sql, $array = true, $use_cache = false); //update position of other module then position is upper or equal to this module position foreach ($result as $value) { $p = $value['position'] + 1; $data = array('position' => $p); $where = "`id_module` = '".$value['id_module']."' AND `id_hook` = '15'"; Db::getInstance()->update('ps_hook_module', $data, $where); } //finally update the position of this module $data = array('position' => $module_position); $where_module = "`id_module` = '".$id_module."' AND `id_hook` = '15'"; Db::getInstance()->update('ps_hook_module', $data, $where_module); return true; } ?> Par contre si je le fait sans utiliser la methode update() comme ceci cela fonctionne nickel <?php private function setModulePositionIntoHookDisplayTop() { //gets the future position for this module into the displayTop hook $sql = "SELECT `position` FROM `ps_hook_module` WHERE `id_module` = 27 AND `id_hook` = 15;"; $module_position = Db::getInstance()->getValue($sql, $use_cache = false); //gets the id for this module into the displayTop hook $sql = "SELECT `id_module` FROM `ps_module` WHERE `name` = '" . $this->name . "';"; $id_module = Db::getInstance()->getValue($sql, $use_cache = false); //gets rows for the displayTop hook where position is upper to the future position of this module $sql = "SELECT * FROM `ps_hook_module` WHERE" . " `position` >= (SELECT `position` FROM `ps_hook_module` WHERE `id_module` = 27 AND `id_hook` = 15)" . " AND `id_hook` = 15" . " AND `id_module` NOT IN (SELECT `id_module` FROM `ps_module` WHERE `name` = '" . $this->name . "');"; $result = Db::getInstance()->executeS($sql, $array = true, $use_cache = false); //update position of other module then position is upper or equal to this module position foreach ($result as $value) { $p = $value['position'] + 1; $sql = "UPDATE `ps_hook_module` SET `position` = '" . $p . "' WHERE `id_module` = '" . $value['id_module'] . "' AND `id_hook` = '15';"; Db::getInstance()->execute($sql); } //finally update the position of this module $sql = "UPDATE `ps_hook_module` SET `position` = '" . $module_position . "' WHERE `id_module` = '" . $id_module . "' AND `id_hook` = '15';"; Db::getInstance()->execute($sql); return true; } ?> Si quelqu'un serai me dire ce que j'ai raté avec la méthode update() Merci d'avance. Link to comment Share on other sites More sharing options...
BeRoots Posted August 26, 2016 Author Share Posted August 26, 2016 Arf oui en effet. Sans suffix Encore merci pour votre aide précieuse... J'avais pas les yeux ouvert aujourd'hui... 1 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