We want to update stock status with sql query. This query worked and products status does as out of stock in product page. But when i did clearing cache, products is appearing in stock

when i check products in admin panel, products is appearing in stock.

Does magento has function for product status change?

$query = "UPDATE cataloginventory_stock_status SET stock_status = 0 WHERE product_id=".$product_id;

Thanks.

New contributor
epica is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
up vote 0 down vote accepted

try this query, in will prevent product appears on the website searching result and although product page can be accessed on the frontend by url, it cannot be added to cart :

$query = "UPDATE cataloginventory_stock_item SET is_in_stock = 0 WHERE product_id=".$product_id;

hope this works

  • thanks @mrfizh, this query worked. i have a one more question. How can i update stock qty with sql query? $query = "UPDATE cataloginventory_stock_status SET stock_status = 0 WHERE product_id=".$product_id; I tried this code but i don't get positive result. – epica Nov 9 at 7:15
  • glad to know it works. you can update the stock quantity by change the column on my answer above to be like this : $query = "UPDATE cataloginventory_stock_item SET qty = 100 WHERE product_id=".$product_id; – mrfizh Nov 9 at 7:20
  • thank you so much, query is worked. – epica Nov 9 at 7:33
  • okay you're welcome :) – mrfizh Nov 9 at 7:40

Your Answer

epica is a new contributor. Be nice, and check out our Code of Conduct.
 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.