Jump to content

Executing a hook from external PHP script


Nabbolo

Recommended Posts

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 by Nabbolo (see edit history)
Link to comment
Share on other sites

@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

  • 7 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...