phunter121 Posted February 21, 2011 Share Posted February 21, 2011 Hi guysThis 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? 1 Link to comment Share on other sites More sharing options...
Radu Posted February 22, 2011 Share Posted February 22, 2011 from classes/Product.php check updateQuantity function Link to comment Share on other sites More sharing options...
phunter121 Posted February 22, 2011 Author Share Posted February 22, 2011 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. 1 Link to comment Share on other sites More sharing options...
Radu Posted February 22, 2011 Share Posted February 22, 2011 for db queries use: $result = Db::getInstance()->ExecuteS('SELECT *.... Link to comment Share on other sites More sharing options...
Burhan BVK Posted February 22, 2011 Share Posted February 22, 2011 You should be able do that in one query: Db::getInstance()->Execute('UPDATE pss_product AS p SET p.quantity=(SELECT Sum(quantity) FROM pss_product_attribute AS pa WHERE pa.id_product=p.id_product GROUP BY pa.id_product ) WHERE 1'); Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now