Jump to content

Updating Product Quantities


rseigel

Recommended Posts

So, it seems that the quantity field is no longer used in the product table and is instead pulled from the stock_available table. Thanks for the hour of total confusion Presta developers. :angry::D

 

I'm trying to update the quantities using a script outside of Presta (dropshipping - I pull the stock availability from them daily). It was working fine until the quantity field moved.

 

Here's the SQL I'm trying to run:

 

UPDATE stock_available
SET stock_available.quantity = 1
FROM stock_available
INNER JOIN product
ON stock_available.id_product = product.id_product
WHERE product.supplier_reference = 'BKFLAGPL';

 

The real script uses variables for stock_available.quantity and product.supplier_reference. I'm just trying to get the basic SQL to work.

 

I get the following error:

 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM stock_available INNER JOIN product ON stock_available.id_product = product.' at line 3

 

Any ideas on where I'm going wrong?

  • Like 1
Link to comment
Share on other sites

I found this in controllers/admin/AdminProductsController.php

 

StockAvailable::setQuantity($product->id, (int)Tools::getValue('id_product_attribute'), (int)Tools::getValue('value'));

 

Does anyone know if this is on the right track?

  • Like 1
Link to comment
Share on other sites

Here's the answer if anyone is interested.

 

 

UPDATE

stock_available, product

SET

stock_available.quantity = 1

WHERE

stock_available.id_product = product.id_product

AND

product.supplier_reference = 'BKFLAGPL';

 

So the ultimate code is:

 

mysql_query("UPDATE stock_available, product SET stock_available.quantity = '$quantity' WHERE stock_available.id_product = product.id_product AND product.supplier_reference = '$supplier_reference'")
  or die(mysql_error());

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 3 months later...
  • 2 months later...
  • 2 years later...

Very happy to have found this old post as I am updating my quantities from an external DB and was pulling my hair out.

 

If you have combinations of products you need to update them using this...

UPDATE `stock_available` sa, `product_attribute` pa
SET sa.`quantity` = 1
WHERE sa.`id_product_attribute` = pa.`id_product_attribute`
AND pa.`reference` = 'MyProductReferenceXX'
Link to comment
Share on other sites

 

Very happy to have found this old post as I am updating my quantities from an external DB and was pulling my hair out.

 

If you have combinations of products you need to update them using this...

UPDATE `stock_available` sa, `product_attribute` pa
SET sa.`quantity` = 1
WHERE sa.`id_product_attribute` = pa.`id_product_attribute`
AND pa.`reference` = 'MyProductReferenceXX'

 

thank you for sharing this sql snippet

may i know what ps verison you have ?

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

Hi, can anyone find solution for external update by quantity Exec('update product')?

 

i explain the situation better:
i update via DB prestashop my stock, with automatic updates from Massive update Inventory.
At the same time, on my prestashop i have a module that connects prestashop stock with my ebay and amazon seller stock. This one is updated every time there is an "hook" updating the products qty (for example, a product is sold). Massive update Inventory doesn't use hooks or scripts but for what i know changes the value of the stock directly. So everytime Massive update Inventory does its update it changes in prestashop but not in ebay and amazon. 

Thanks in advance
Best Regards

  • Like 1
Link to comment
Share on other sites

  • 7 years later...

Hi, could you help me figure out which query I need to use to do this:


assign quantity 0 to all products that have inactive status in the prestashop catalog.


I use prestashop 1.6.
Thanks to those who will help me

Link to comment
Share on other sites

  • 9 months later...
On 1/4/2016 at 9:59 AM, timwelch said:

Very happy to have found this old post as I am updating my quantities from an external DB and was pulling my hair out.

 

If you have combinations of products you need to update them using this...

UPDATE `stock_available` sa, `product_attribute` pa
SET sa.`quantity` = 1
WHERE sa.`id_product_attribute` = pa.`id_product_attribute`
AND pa.`reference` = 'MyProductReferenceXX'

So to update you need to use reference column in query?

Query:

$query = "UPDATE `"._DB_PREFIX_."stock_available` SET quantity='66' WHERE (id_product_attribute = '".$ID_product_attribute."' AND id_product = '".$ID_product."' )";
    

will not work?

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...