Prestashop: Webservices: udpating stock available do not call Hook::exec('actionUpdateQuantity'

Created on 22 Mar 2019  路  8Comments  路  Source: PrestaShop/PrestaShop

Describe the bug
I experienced, that Prestashop does not call Hook::exec('actionUpdateQuantity',...) when one puts (HTTP PUT) new quantity of a product using webservice request to the resource . In my opinion, it should.

Probably it affects only products without an attribute (id_attribute = 0).

I tested it in 1.6.1.7 Prestashop. However i see that in the development branch nothing changed in this code. So in prestashop 1.7.x code will behave excatly the same.

My proposal to this issue is to modify postSave() function in StockAvailable.php class:


public function postSave()
    {
        if ($this->id_product_attribute == 0) {
$id_shop = (Shop::getContext() != Shop::CONTEXT_GROUP && $this->id_shop ? $this->id_shop : null);
            $quantity = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
            SELECT quantity as quantity
            FROM '._DB_PREFIX_.'stock_available
            WHERE id_product = '.(int)$this->id_product.'
            AND id_product_attribute = 0 '.
                    StockAvailable::addSqlShopRestriction(null, $id_shop)
                    );
            Hook::exec('actionUpdateQuantity',
                    array(
                            'id_product' => $this->id_product,
                            'id_product_attribute' => 0,
                            'quantity' => (int)$quantity
                    )
                    );
            Cache::clean('StockAvailable::getQuantityAvailableByProduct_'.(int)$this->id_product.'*');
            return true;
        }

 ....

If it would be helpful, I can create an appropriate pull request.
Best regards,

1.7.5.2 Bug Minor PR available To Do WS

All 8 comments

Hi @michjoh,

Thanks for your report.
@PrestaShop/prestashop-core-developers what do you think?

Thanks!

Hi @michjoh,

indeed the hook should be called at all times. This attribute check seems weird to me as well.
I don't see any reason why products with combination should not call this hook. Please feel free to propose a pull request for this issue. The core team is currently quite busy with the coming freeze of the 1.7.6 version, but we will look at your PR to integrate it in the next version.

Best regards.

Ok i will prepare PR in my spare time.
Best regards,

Hi @michjoh,

Thanks for your feedback.
Feel free to open a new one when needed.
Thanks!

Hi @michjoh,

Thanks for the PR.
I will re-open this issue.
I will add it to our bug roadmap.

Thanks!

I write here what I wrote on #17750

We tested on PS 1.7.5.2 with a product with attribut, the hook "actionUpdateQuantity" is run.
But without attribut the hook is not run.

We tried the modification (#13213) of @michjoh but:

  • if product has attribut, hooks are not run.
  • if the product has not attribut, hooks are run.

It's opposite than before the modification...

PS 1.7.5.2
php 7.2

Describe the bug
I experienced, that Prestashop does not call Hook::exec('actionUpdateQuantity',...) when one puts (HTTP PUT) new quantity of a product using webservice request to the resource . In my opinion, it should.

Probably it affects only products without an attribute (id_attribute = 0).

I tested it in 1.6.1.7 Prestashop. However i see that in the development branch nothing changed in this code. So in prestashop 1.7.x code will behave excatly the same.

My proposal to this issue is to modify postSave() function in StockAvailable.php class:


public function postSave()
    {
        if ($this->id_product_attribute == 0) {
$id_shop = (Shop::getContext() != Shop::CONTEXT_GROUP && $this->id_shop ? $this->id_shop : null);
          $quantity = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
          SELECT quantity as quantity
          FROM '._DB_PREFIX_.'stock_available
          WHERE id_product = '.(int)$this->id_product.'
          AND id_product_attribute = 0 '.
                  StockAvailable::addSqlShopRestriction(null, $id_shop)
                  );
          Hook::exec('actionUpdateQuantity',
                  array(
                          'id_product' => $this->id_product,
                          'id_product_attribute' => 0,
                          'quantity' => (int)$quantity
                  )
                  );
          Cache::clean('StockAvailable::getQuantityAvailableByProduct_'.(int)$this->id_product.'*');
          return true;
        }

 ....

If it would be helpful, I can create an appropriate pull request.
Best regards,

i have tested it and its working for 1.7.6.5

i was creating syncronisation of stock between diffrent prestahsop setup and i want that if stock updated on 1 then it will update stock on second shop 2 and now it works

Was this page helpful?
0 / 5 - 0 ratings