Jump to content

Hook executed every time


alaaghribi

Recommended Posts

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

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

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...