AcidLava Posted October 10 Share Posted October 10 Hello, Does anyone have a free solution or an SQL query to update the stock of all products and their variations to a specific value? Thank you. Link to comment Share on other sites More sharing options...
Knowband Plugins Posted October 14 Share Posted October 14 Hi, Yes, you can use an SQL query to update the stock of all products and their variations in PrestaShop to a specific value. Below is a query that updates the stock for all products and combinations to a desired value (e.g., 100): UPDATE ps_stock_available SET quantity = 100 WHERE id_product > 0; If you don't want to use the SQL, then you can use the PrestaShop's StockAvailable class. $products = Db::getInstance()->executeS('SELECT id_product FROM '._DB_PREFIX_.'product'); foreach ($products as $product) { $id_product = (int)$product['id_product']; StockAvailable::setQuantity($id_product, 0, $new_quantity); $combinations = Db::getInstance()->executeS('SELECT id_product_attribute FROM '._DB_PREFIX_.'product_attribute WHERE id_product = ' . $id_product); foreach ($combinations as $combination) { $id_product_attribute = (int)$combination['id_product_attribute']; StockAvailable::setQuantity($id_product, $id_product_attribute, $new_quantity); } } You can update the code according to your needs. Regards 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