M Iqbal Posted April 8, 2022 Share Posted April 8, 2022 Hello support, I am trying to use hookActionCartSave hook in my custom module but that hooks fire when i go to checkout and add customer information or login customer in Prestashop 1.6 and 1.7. I want the event when user add product to cart. As per Prestashop documentation i try to use actionCartUpdateQuantityBefore but no luck. Can anyone please help. Thank you. Link to comment Share on other sites More sharing options...
Janett Posted April 8, 2022 Share Posted April 8, 2022 hookActionCartSave is called each time a data of Cart has change. So it happens many times on same request. 1.6 you can use actionBeforeCartUpdateQty https://github.com/PrestaShop/PrestaShop-1.6/blob/1.6.1.24/classes/Cart.php#L959 1.7 you can use actionCartUpdateQuantityBefore https://github.com/PrestaShop/PrestaShop/blob/1.7.8.5/classes/Cart.php#L1558 Link to comment Share on other sites More sharing options...
Ress Posted April 8, 2022 Share Posted April 8, 2022 That hook works when you add something to the cart. Is the hook registered? If so, what exactly do you do that doesn't work? Link to comment Share on other sites More sharing options...
M Iqbal Posted April 11, 2022 Author Share Posted April 11, 2022 Basically, I am currently using hook hookActionCartSave , but this hooks fire when i go to checkout page and enter customer address / login customer after adding product to cart. I need an event when a product will be add / remove / qty update in cart. Link to comment Share on other sites More sharing options...
Ress Posted April 11, 2022 Share Posted April 11, 2022 That hook is executed when you add / delete a product, I tell you for sure. Do a simple test, type "exit;" in the hook, and check in the console, on the network, if the execution stops (you can also give a var_dump with a text, to see if it returns that text to you). 1 Link to comment Share on other sites More sharing options...
wolfomat Posted April 28 Share Posted April 28 I have the same problem with version 8. i added a echo with script-tag and then called console.log('hook called'), but nothing happend. but there won't be a console.log, using var_dump creates an error Link to comment Share on other sites More sharing options...
Webkul Solutions Posted April 29 Share Posted April 29 8 hours ago, wolfomat said: I have the same problem with version 8. i added a echo with script-tag and then called console.log('hook called'), but nothing happend. but there won't be a console.log, using var_dump creates an error In PrestaShop, you cannot directly use console.log inside an action hook because action hooks are executed on the server side in PHP, while console.log is a JavaScript function that runs on the client side (browser). You can use PHP debugging methods inside your action hook function, such as: error_log(print_r($params, true)); // to log data to the PHP error log. print_r($params); die(); // to output data directly (useful for quick debugging but will stop execution). Link to comment Share on other sites More sharing options...
WisQQ Posted April 29 Share Posted April 29 11 godzin temu, wolfomat napisał: I have the same problem with version 8. i added a echo with script-tag and then called console.log('hook called'), but nothing happend. but there won't be a console.log, using var_dump creates an error You can use PrestashopLogger for action hooks and then check Logs page in prestashop. Link to comment Share on other sites More sharing options...
wolfomat Posted May 1 Share Posted May 1 that was a good hint. logs are written, i guess i need to study the docs further, in order to implement a correct functionality. however, the logs has shown, that the hooks are called. thanks ! PrestaShopLogger::addLog('hookActionValidateOrder', 3); was a call -> i saw that log 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