I’m running the code bellow via cron jobs in order to disable out-of-stock products from been displayed on my web site. Could anyone who knows the prestashop’s database structure helps me to add an exception for 2 product categories with id 2 & 5 so the script dose not disable products from those categories?
<?php
require_once('./../config/config.inc.php');
$sql = "UPDATE "._DB_PREFIX_."product_shop SET visibility='none' WHERE id_product IN (SELECT id_product FROM "._DB_PREFIX_."stock_available WHERE quantity<=0)";
if (!Db::getInstance()->execute($sql)) die('error!');
?>
Thanks in advance for any help
2
Answers
I figured it out. This is the code in case someone else wants to use it. It works with Prestashop 8 and hides the out-of-stock products except the products assigned to category 5.
You have to adjust your query by adding a WHERE condition to check in ps_category_product table which id_product(s) are not in your id_categories list.
If you want just check by predefined/default product categories, you can just check id_default_category field in ps_product_shop.