kdmonk1 Posted November 4, 2021 Share Posted November 4, 2021 I am currently setting up a cronjob to disable a product when it is sold out. Is there a better way or better script that someone could assist me with? Right now when I run the cronjob, I am getting this error? Cronjob: /usr/local/bin/php "https://mywebsite.com/app/config/product_out_of_stock.php” > /dev/null Error after job runs: usr/local/cpanel/bin/jailshell: -c: line 0: unexpected EOF while looking for matching `"' /usr/local/cpanel/bin/jailshell: -c: line 1: syntax error: unexpected end of file product_out_of_stock.php <?php ini_set('display_errors', 1); $mysql_host = '127.0.0.1'; $mysql_database = 'database'; $mysql_user = 'user'; $mysql_password = 'password'; $db = new PDO("mysql:host=$mysql_host;dbname=$mysql_database", $mysql_user, $mysql_password); $sql = 'UPDATE ps_product_shop SET active=0 WHERE id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity=0)'; $stmt = $db->prepare($sql); if($stmt->execute()){ echo "Success"; }else{ echo "Fail"; } ?> Link to comment Share on other sites More sharing options...
ChristosDs Posted November 15, 2021 Share Posted November 15, 2021 For Prestashop 1.7. I'm have created 2 php files and using the code below for disabling the out of stock products <?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!'); ?> and this one to enable the products when are back in stock <?php require_once('./../config/config.inc.php'); $sql = "UPDATE "._DB_PREFIX_."product_shop SET visibility='both' WHERE id_product IN (SELECT id_product FROM "._DB_PREFIX_."stock_available WHERE quantity>0)"; if (!Db::getInstance()->execute($sql)) die('error!'); ?> I added the files to a subdirectory of the site and I'm running the files as cron jobs. Link to comment Share on other sites More sharing options...
kdmonk1 Posted November 15, 2021 Author Share Posted November 15, 2021 @ChristosDs - Awesome job. I will try it out soon. Link to comment Share on other sites More sharing options...
Aldeag Posted November 15, 2021 Share Posted November 15, 2021 I´m using this free module. Maybe it helps: https://www.sunnytoo.com/31746/hiding-stock-products-free-prestashop-module Link to comment Share on other sites More sharing options...
kdmonk1 Posted November 15, 2021 Author Share Posted November 15, 2021 Thanks @Aldeag, I will try it out. I believe the one I have sunnytoo created but we are removing the empty categories when all the products under that category are disabled. 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