Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

oscommerce – 30 minutes cleanup from cart baskets


include_once("includes/configure.php");
$conn = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD);
mysql_select_db(DB_DATABASE);
$sql = "SELECT `customers_basket_id`,`customers_id`,`products_id`,`customers_basket_quantity`,`final_price`,`customers_basket_date_added`,`auction_product`,`customers_basket_datetime` FROM   `customers_basket` ORDER BY `customers_basket_id` ASC";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
	$products_id = $row["products_id"];
	$customers_id = $row["customers_id"];
	$customers_basket_quantity = $row["customers_basket_quantity"];	
	$total_minutes = 0;
	$customers_basket_datetime = $row["customers_basket_datetime"];
	$total_minutes = date_diff($customers_basket_datetime);
	if ($total_minutes >= 30){			
		$sql = "update products set products_quantity = products_quantity + ".$customers_basket_quantity." where products_id = '" .$products_id. "'";
		mysql_query($sql);
		//echo $sql."
"; $sql = "delete from customers_basket where customers_id = '" .$customers_id. "' AND products_id = '" .$products_id. "'"; mysql_query($sql); //echo $sql."
"; $products_parent_id = 0; $products_parent_id = tep_hasParentID($products_id); //echo 'products_parent_id: '.$products_parent_id."
"; if ($products_parent_id>0) { $sql = "update `products` set `products_quantity` = 0, `products_status` = 1 where `products_id` = '".$products_parent_id."'"; mysql_query($sql); //echo $sql."
"; } //echo "
"; } //echo "
"; } mysql_free_result($result); function tep_hasParentID($products_id) { global $conn; $prod_query = mysql_query("SELECT `products_parent_id` FROM `products` WHERE `products_id`='".$products_id."'"); $prods = mysql_fetch_array($prod_query); return $prods['products_parent_id']; } function date_diff($start, $end="NOW"){ $sdate = strtotime($start); $edate = strtotime($end); $time = $edate - $sdate; $phour = ($edate - $sdate) / 3600; $prehour = explode('.',$phour); $premin = $phour-$prehour[0]; $min = explode('.',$premin*60); $presec = '0.'.$min[1]; $sec = $presec*60; $total_mins = 0; if($prehour[0]>0) $total_mins = ($prehour[0] * 60) + $min[0]; else $total_mins = $min[0]; return $total_mins; }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: