alaaghribi Posted November 28, 2016 Share Posted November 28, 2016 I'm using a hook to create a product when clicking on a button. In the module.php file I'm using this function : public function hookActionProductAdd() { //code to create a product } In the module.tpl file I'm creating a button, its onClick execute the hook : <button onclick="createProduct()">Create product</button> And at the end of the file I add the script code : <script> function createProduct() { {hook h='ActionProductAdd'} } </script> I don't know why the product is created every time I access or reload the module's page . THank you for your help. Link to comment Share on other sites More sharing options...
alaaghribi Posted November 28, 2016 Author Share Posted November 28, 2016 Or is there any other way to achieve that ? Executing a hook when pressing a button . Thank you . Link to comment Share on other sites More sharing options...
NemoPS Posted December 2, 2016 Share Posted December 2, 2016 That's absolutely not the way it works.You have to instanciate a new Product class to create a product. The hook is only meant to display in templates with that syntax. Also, the hook doesn't create a product, it runs WHEN you create a product, to perform other actions 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