Jump to content

catch Id product when update a product


RosarioD

Recommended Posts

I realized a module that use a hook method (I called it hookActionProductAdd) to take the product id whenever the user create a new product through the Prestashop's back-end (using the actionProductAdd hook, that is registered in the install method of the module). I want to do the same thing using instead the hook actionProductUpdate. I will link the code below.

 

This is the module's method that handles the hook:

public function hookActionProductAdd($params)
{
 if (isset($params['product']->id)) { echo "Here is the ID: ".$params['product']->id; }
 else { echo "ID not setted"; }
}

In the install method, i have the follow code:

if (!parent::install() || !$this->registerHook('actionProductUpdate')
                       || !$this->registerHook('actionProductAdd')
     )
     return false;
 return true;

 

In this case (the case a new product is added) the ID is correctely shown. But if I use the hookActionProductUpdate method (that is the same method as the above hookActionProductUpdate) the ID is not returned.

 

I wish to find a unique way to identify a product's ID when a user update the product through the back-end of Prestashop.

 

 

Link to comment
Share on other sites

There are these hooks in /controllers/admin/AdminProductsController.php (v1.6)

 

Hook::exec('actionProductAdd', array('product' => $product));

Hook::exec('actionProductAdd', array('product' => $this->object));

Hook::exec('actionProductUpdate', array('product' => $this->object));

 

So it would work as you need.

Link to comment
Share on other sites

Yeah, I finally found what was wrong. The trick is that the $params that is given to the hookActionProductUpdate method saved the product's ID in another location, always inside the $params array. I accessed the product's it through $params['id_product'].

 

Thank you anyway for your help and support :)

Edited by RosarioD (see edit history)
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...