After a new product is saved in the backoffice, I need to send some information to an external API. I have overridden the Product class and added the code at the end of the add() function, right after
Hook::exec('actionProductSave', array('id_product' => (int) $this->id, 'product' => $this));
and before the return statement. All the info is sent correctly (name, price etc), except for the default category, which, for some reason, is always sent as being the Home category, regardless of what is actually selected. But if I go and see the product in the backoffice, the correct category appears, not Home.
I tried getting the category from $this->id_default_category, and I also tried selecting it from the database, the result is the same.
My only conclusion is that the category is updated sometime after the add() function is executed, but I just can't figure out where. Any help to point me in the right direction would be appreciated.
I would suggest you to create a very simple module that triggers hookActionProductUpdate. This way you can use the hook parameter ($params) to get product data and send it directly to external API without touching the Prestashop core.
You can find out more here : https://devdocs.prestashop.com/1.7/modules/introduction/