Jump to content

SQL Query To Update Product Quantity With Attribute Matching Reference


arunzaks

Recommended Posts

Hello,

I am looking for an sql query to update 'products with attributes' matching particular reference number,

I managed to find a query with select statement. 

Looking for a query to update the stock quantity via sql,

SELECT s.quantity FROM ps_product p LEFT JOIN ps_product_attribute pa ON (p.id_product = pa.id_product) LEFT JOIN ps_stock_available s ON (p.id_product = s.id_product AND (s.id_product_attribute = pa.id_product_attribute)) WHERE pa.reference ='my reference'

I need to update s.quantity from the above statement.

Any help is really appreciated.

Thanks in advance.

 

 

Link to comment
Share on other sites

It is better to use the Prestashop function to update.

$reference = 'xadsed';
$quantity = 67;
$query = "SELECT * FROM "._DB_PREFIX_."product_attribute WHERE reference = '".$reference."'";
$attr_info = Db::getInstance()->getRow($query);
if ($attr_info) {
  StockAvailable::updateQuantity($attr_info['id_product'], $attr_info['id_product_attribute'], $quantity);
}

 

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...