sicine Posted August 18, 2014 Share Posted August 18, 2014 (edited) hello everyone, i'm developing a module where I have to to add my products to an other table 'products' in my prestashop database. well i did it using the AddProduct hook and it works perfectly. now I want to work on the delete function. i tried to do the same thing with the appropriate hook but the product is not deleted from the products table. NB: my 'products' table does not have any prefix this is my hookDeleteProduct function : public function hookDeleteProduct($params) { if (!isset($params['product']->id)) return false; $id_product = (int)$params['product']->id; $sql = 'DELETE FROM products WHERE ID ='.$id_product ; Db::getInstance()->execute($sql); } please help Edited August 18, 2014 by sicine (see edit history) Link to comment Share on other sites More sharing options...
Paul C Posted August 18, 2014 Share Posted August 18, 2014 (edited) Assumuming that you add a $this->registerHook('actionObjectProductDeleteAfter') in the module's install() method (and reset or uninstall/install the module before testing) I would probably be tempted to use: public function hookActionObjectProductDeleteAfter($params) { $product = $params['object']; if ($product instanceof Product) Db::getInstance()->execute('DELETE FROM products WHERE ID ='.$product->id); } Edited August 18, 2014 by Paul C (see edit history) 1 Link to comment Share on other sites More sharing options...
sicine Posted August 18, 2014 Author Share Posted August 18, 2014 thank you so much Paul for your reply well i tried it but its not working, sorry i'm a newbie pestashop developer and i'm really confused... Link to comment Share on other sites More sharing options...
Paul C Posted August 18, 2014 Share Posted August 18, 2014 Can you post an export of the table structure? Have you looked in the server error log to see if there's an error? The reason I mention an uninstall/install is because people often forget that the registerHook() call is only made during an install, so you can't add extra functions to a module that's already installed and expect them to work 1 Link to comment Share on other sites More sharing options...
sicine Posted August 18, 2014 Author Share Posted August 18, 2014 i did register my hook but i forgot to uninstall my module now i did it and its working perfectly thank you so much Paul 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