Prestashop: hookActionUpdateQuantity not returning quantity in parameters when a combination quantity is edited

Created on 25 Jun 2019  路  17Comments  路  Source: PrestaShop/PrestaShop

Describe the bug

When using hookActionUpdateQuantity in a module to detect a quantity change from a user,
if the product have combinations , there is no combination quantity information returned in the hook parameter. Since hookActionUpdateQuantity is meant to be used for quantity change,
it would be expected to have "new" combination quantities details there.

Steps to reproduce the behavior:

  1. Register hookActionUpdateQuantity in a module
  2. Try editing the quantity in a simple product
  3. Do a $params var_dump
  4. Try editing the quantity in a variation product
  5. Do a $params var_dump
  6. Compare results

Screenshots
$params for product without variations => https://www.screencast.com/t/emEqrvKmK
$params for product with variations => https://www.screencast.com/t/G4hyhSjxk

Additionnal information
PrestaShop version: 1.7.5.2

A silly "proof of concept" module to easily reproduce had been uploaded here :
https://gofile.io/?c=0l4Mbm

1.7.5.2 Bug CO Combinations Duplicate Products

All 17 comments

Hi @gennaris,

I did not manage to reproduce the issue with PS1.7.5.2 & PS1.7.6.0rc1.
I attached a video record
https://drive.google.com/file/d/1tVNgqkoJ5lBw2cDpoTaKmJAfY7n3QA3Y/view
Thanks to check & feedback.

Hi @khouloudbelguith ,
thank you for your time.

Indeed I confirm that a quantity parameter is returned correctly in the hook parameter in the latest 1.7.6.0 nightly build, as per your attached video.

However there is no way to see the specific customer "edited" combination quantities , as the returned quantity is always the sum of all variation quantities with id_product_attribute = 0.

So there is still no way to intercept the modified variation quantity value inside this hook, to send it, for example, to an external API from a module during a product save / update,
without the needing to reload the product afterwards.
Correct me if I'm wrong, but I would expect to have these details from an hook named that way.

Thank you !

@gennaris, thanks for your feedback.
As you can see in our documentation: https://devdocs.prestashop.com/1.7/modules/concepts/hooks/list-of-hooks/
The parameters of the actionUpdateQuantity:

array(
  'id_product' => (int) Product ID,
  'id_product_attribute' => (int) Product attribute ID,
  'quantity' => (int) New product quantity
);

Thanks!

@khouloudbelguith thanks.

So it looks like there is no available hook / way to get whole product combinations modified quantity from backoffice DURING a single product quantity update / save ?

I noticed that even calling a StockAvailable::getQuantityAvailableByProduct inside a hookActionProductSave with id_product_attribute parameter I still get the "old" quantities so it looks like the hook is called before the actual stock update.

This makes it necessary to "double save" a product so that a module can intercept the new quantities.

Is it possible to ping the developers to have a little clarification on this or if I'm missing something ?

Thanks !

@gennaris, thanks for your feedback.
The hook "ActionProductSave" is called while saving products.
In your case, you need to use the "actionProductUpdate" hook, it is displayed after a product has been updated.
This hook is triggered when running ajaxProcessProductQuantity.
For more details, you can follow our documentation: https://devdocs.prestashop.com/1.7/modules/concepts/hooks/list-of-hooks/

Thanks to check & feedback.

@khouloudbelguith thanks for your patience !

Yes I did tried "actionProductUpdate" already but the result is the same, the hook is called before the quantity gets written in database (both for id_product_attribute = 0 and various id_product_attribute(s) ) so if I call a StockAvailable::getQuantityAvailableByProduct method inside the hook, I am still getting the "old" quantites.

See this sample video where I have transplanted my module in actionProductUpdate and did a var_dump of quantity before / after saving : https://www.screencast.com/t/RcJAqp3s3

Thanks !

@gennaris, thanks for these clarifications.
Yes, I have the same issue with PS1.7.5.2 & PS1.7.6.0rc1.
ping @PrestaShop/prestashop-core-developers what do you think?

Thanks!

I know this is not a critical one, but a follow-up would be really appreciated.

@gennaris, I just pinged our developers on this issue.

Thanks!

I guess they should have some network problem :-)

Ping @khouloudbelguith - Any news ?

I have recently returned to the problem because I would like to solve it, I also tried these two "save-related" hooks

actionProductAttributeUpdate
actionObjectProductUpdateAfter

and the problem is always the same, the returned quantity is always the one BEFORE the product update and there's no way to intercept new combination quantities during a product save.

@PrestaShop/prestashop-core-developers friendly reminder :)

FYI - I also found this hook actionObjectStockUpdateAfter in ps_hook table,
but it looks like is never executed in core source code.

I am not sure if it is a 1.6 leftover (because of removed ASM) or something new ?

Hello @khouloudbelguith was there any development on this subject? I'm being impacted by this problem too and this leads to stale informations, especially when you have to export data to other systems.

Thank you

HI @Uff182,

Sorry not yet.
But PrestaShop is an open-source project, so it can be solved before if someone submits a pull request to solve it.

Thanks!

Hi @Uff182,

We are awre of this issue, it is added to our debug roadmap.
Your ticket is a duplicate of https://github.com/PrestaShop/PrestaShop/issues/20715
So, I close it.
Thanks!

Was this page helpful?
0 / 5 - 0 ratings