philoupin Posted July 19, 2020 Share Posted July 19, 2020 Hi, my custom module is listening to "actionProductUpdate" so additional info can be saved during product update in Admin. However when I "save" a product by hitting the "Save" button on the product information page in Admin, the hook "actionProductUpdate" gets called twice. This is on PS 1.7.6.5. The hook fires once in file classes/Product.php line 644 inside function "update" and in src/Adapter/Product/AdminProductWrapper.php on line 205 inside function "processQuantityUpdate". Is it really intended that the same hook is called twice during one script execution? My module is now called twice during product update and I have to write some ugly code to not insert the same data twice into the DB during the second call. In src/Adapter/Product/AdminProductWrapper.php ist says: // Hook triggered by legacy code below: actionUpdateQuantity('id_product', 'id_product_attribute', 'quantity') StockAvailable::setQuantity((int) $product->id, $forAttributeId, $quantity); Hook::exec('actionProductUpdate', array('id_product' => (int) $product->id, 'product' => $product)); So maybe the hook should rather be called something like "actionProductUpdateQuantity" ? Thanks for any hints on how to elegantly handle the second hook call, in case this is indeed intended behaviour of PS. Link to comment Share on other sites More sharing options...
Appwards Posted April 22, 2021 Share Posted April 22, 2021 It's an old post, but for people searching for the same thing, here's what I use to avoid this. Note that I haven't taken much time to find the cause of this double execution, but I do know that my module is the only module listening to that hook. Also I know my module isn't listed twice for the same hook in the ps_hook_module table. Instead of using a session, I use the context which is available in your yourmodule.php file if (isset($this->context->controller->blockDoubleStockUpdateExecution)) return true; else $this->context->controller->blockDoubleStockUpdateExecution = true; Hope it helps someone. 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