Nabbolo Posted March 13, 2015 Share Posted March 13, 2015 (edited) Hello community!I have a quite simple question. I update quantities in the database using a PHP script (in ps_stock_available). I would like that after every updated quantity, the script calls one of the hooks that Prestashop uses, for example when I go into a product from back office and click "Save" button. This is needed to propagate correctly this change to other modules working with quantities. This is a pseudocode of what is done in my script: <?php require_once(dirname(__FILE__).'/../config/config.inc.php'); require_once(dirname(__FILE__) . '/../init.php'); acquire_products(); foreach(product) { update_quantitiy_DB($id_product); Hook::exec('UpdateProduct', array('product' => $id_product)); } ?> So each iteration I update the quantity in MySQL for the product ID contained in $product_id, then I would like to execute the hook for that product ID. I have tried many configurations for the argument of Hook::exec() but none of them worked. I get no errors, but I don't get the results that I have when I press the "Save" button in back office. How should it be written? Edited March 13, 2015 by Nabbolo (see edit history) Link to comment Share on other sites More sharing options...
Nabbolo Posted March 14, 2015 Author Share Posted March 14, 2015 (edited) I have tried with "actionProductUpdate" "actionProductSave" hook as well, but with no success. Any idea? Edited March 14, 2015 by Nabbolo (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted March 15, 2015 Share Posted March 15, 2015 Have you tried actionUpdateQuantity? Link to comment Share on other sites More sharing options...
bellini13 Posted March 15, 2015 Share Posted March 15, 2015 This is needed to propagate correctly this change to other modules working with quantities. How you looked at the modules in question, and actually determine what hooks they are using? Link to comment Share on other sites More sharing options...
Nabbolo Posted March 16, 2015 Author Share Posted March 16, 2015 @rocky: yes, I have read all the PS classes in search or hook names to try, and I have tried that too. @bellini13: I looked into the code of my module and looked for the hooks that were handled (registered and handled by a hookNameOfTheHook() function) In the end I managed to get it work. The problem was about the parameter assignment: the ID product must be passed as 'id_product', and not as 'product', so the code to be used it the following: Hook::exec('updateProduct', array('id_product' => $product_id)); Link to comment Share on other sites More sharing options...
ietax Posted November 14, 2015 Share Posted November 14, 2015 How can I write PHP script?I'd like to recevive more information for do it...How did you resolve? Thanks 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