RosarioD Posted November 12, 2014 Share Posted November 12, 2014 Hi, I'm new in prestashop. In my project i would catch the product's id when the user update it. Somebody can help me? Link to comment Share on other sites More sharing options...
tuk66 Posted November 12, 2014 Share Posted November 12, 2014 Where? In Back Office, Front Office, module? Link to comment Share on other sites More sharing options...
RosarioD Posted November 12, 2014 Author Share Posted November 12, 2014 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 More sharing options...
tuk66 Posted November 12, 2014 Share Posted November 12, 2014 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 More sharing options...
RosarioD Posted November 12, 2014 Author Share Posted November 12, 2014 (edited) 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 November 12, 2014 by RosarioD (see edit history) 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