Jump to content

Cronjob to disable sold out stock


kdmonk1

Recommended Posts

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

  • 2 weeks later...

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

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