Hamendra Sunthwal Posted December 29, 2020 Share Posted December 29, 2020 I am trying to execute some code when the product is created/added in prestashop. I have used Hook ActionProductAdd but it does not execute, on product add. Can we really use this hook ? & how to use it so it gets executed ? Any thoughts on this ? Thankyou Link to comment Share on other sites More sharing options...
Guest Posted December 29, 2020 Share Posted December 29, 2020 (edited) public function hookActionProductSave($params) { $product_id = $params['id_product']; $product = $params['product']; // Product Object } Edited December 29, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted December 29, 2020 Author Share Posted December 29, 2020 Thanks for your reply, but this hook execute every time when i save product. I only want to execute code when product is created. Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted December 29, 2020 Author Share Posted December 29, 2020 Any thoughts ? Link to comment Share on other sites More sharing options...
Guest Posted December 29, 2020 Share Posted December 29, 2020 hookActionObjectProductAddAfter Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted December 29, 2020 Author Share Posted December 29, 2020 You mean public function install() { if (!parent::install() !$this->registerHook('actionObjectProductAddAfter')) { return false; } return true; } public function hookActionObjectProductAddAfter(array $params){ } Is this ok ? Link to comment Share on other sites More sharing options...
Guest Posted December 29, 2020 Share Posted December 29, 2020 public function hookActionObjectProductAddAfter($params){ } Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted December 29, 2020 Author Share Posted December 29, 2020 Thankyou very much, i will test it. Can you please advise me on this - https://www.prestashop.com/forums/topic/1039234-how-to-create-custom-field-in-product-edit-page-admin/?tab=comments#comment-3293413 ? Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted December 31, 2020 Author Share Posted December 31, 2020 Hello public function install() { if (!parent::install() !$this->registerHook('actionObjectProductAddAfter')) { return false; } return true; } public function hookActionObjectProductAddAfter($params){ } This is not working even if try to create new product this hook calls, it calls on edit new product page. Link to comment Share on other sites More sharing options...
Guest Posted December 31, 2020 Share Posted December 31, 2020 (edited) After create product: hookActionObjectProductAddAfter Before create product: actionObjectProductAddBefore https://devdocs.prestashop.com/1.7/modules/concepts/hooks/list-of-hooks/ actionObject<ObjectName>AddBefore Located in: /classes/ObjectModel.php actionObject<ObjectName>AddAfter Located in: /classes/ObjectModel.php actionObject<ObjectName>UpdateBefore Located in: /classes/ObjectModel.php actionObject<ObjectName>UpdateAfter Edited December 31, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted December 31, 2020 Author Share Posted December 31, 2020 Thankyou very much let me check in code. Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted December 31, 2020 Author Share Posted December 31, 2020 (edited) According to you which hook will be most appropriate if i want to display something once a new product is created in prestashop ? Edited December 31, 2020 by Hamendra Sunthwal (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted December 31, 2020 Share Posted December 31, 2020 When you use before, you have no product information and you have to find the product id from the database (select max (id_product)) and add +1 to it, when you use after, you have all the product information. Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted December 31, 2020 Author Share Posted December 31, 2020 Great thankyou, can we execute some code on order place ? Just like some hook which is called when order is placed ? I appreciate your help Link to comment Share on other sites More sharing options...
Guest Posted January 1, 2021 Share Posted January 1, 2021 (edited) I do not understand your question. I gave you a link to a list of hooks. Just find the hook you need. Use Ctrl + F = search. Search for actionCart, actionOrder, displayOrder, actionCustomer, etc. Edited January 1, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Hamendra Sunthwal Posted January 1, 2021 Author Share Posted January 1, 2021 Thankyou 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