Jump to content

Updating quantities and price on ps_product


Recommended Posts

Hi guys

This has can up in a number of posts, but I cannot see a resolution.

I have a simple script that reads a .csv file containing price and quantity updates and applies these to the ps_product_attribute table.

The update is fine, but because the quantity of the 'parent' product (in ps_product) is not updated, the product is still showing out of stock in the FO. From what I can see, the qty in the ps_product table is the total quantity of all its attributes quantities.

Is there a simple way to to call a function/class that would trigger the ps_product record to recalculate its quantity from its attributes?

  • Like 1
Link to comment
Share on other sites

Thats for that, I got round it in the mean time by having this code in the php script.

$query = "SELECT id_product, Sum(quantity) AS SumOfquantity
   FROM pss_product_attribute GROUP BY id_product";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
   mysql_query( "UPDATE pss_product SET quantity=$row[1]
        WHERE id_product = $row[0]") or die(mysql_error());

It basically gets all the attributes (grouped by product code and summed by quantity), then updates the corresponding product record. Works a treat, but I fear not the proper way to be accessing the DB.

  • Like 1
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...