I’m developing a simple module that hooks to actionUpdateQuantity hook. So, every time the stock of a product is updated I must update the stock of other products.
But, to update the stock I call stockAvailable object, which trigger the actionUpdateQuantity hook. So, I have a endless loop.
Then I tried to manually update the stock directly on the database using SQL, but this have the problem that other modules don’t “see” the stock updates. So, modules like MailAlert, ebay or Amazon don’t update stock correctly.
I’m a bit stuck here.
How can I update the stock without enter a loop ?
Thanks!
2
Answers
I had similar issue before and think this is not best way but worked for me. Idea is to add class variable in your module:
then in
hookActionProductUpdate
function first check that variable and later after you done saving data change its valueAnother way to do this is, in your module when you submit new quantity make sure you also submit product id and attribute id. Then in your hook you can do a check.
Everytime the hook
actionUpdateQuantity
triggers you have a$params
array of product whose quantity is being updated.This way your hook will run only once when you are updating quantity of a product from your module (form?). As you update other products quantity they will also trigger this hook but since the data in
$params
array is different than your POST’ed data, the hook method will return false.