Location: PHPKode > projects > Uiga Cart > library/checkout-functions.php
<?php
require_once 'config.php';
require_once 'common.php';
/*********************************************************
*                 CHECKOUT FUNCTIONS 
*********************************************************/
function isEmptyOrder()
{
	$isEmptyOrder = false;
	
	$sql="SELECT * FROM tbl_temp_order";
	$result = dbQuery($sql);
	if (dbNumRows($result) == 0) {
		$isEmptyOrder = true;
	}	
	return $isEmptyOrder;
}
function tempSave($id)
{
	$orderId       = 0;
	$shopConfig = getShopConfig();
	$shippingCost  = $shopConfig['shippingCost'];	
	 
				
		$cartContent = getCartContent();
		$numItem     = count($cartContent);
		
		// save order & get order id
		$sql = "INSERT INTO tbl_temp_order(user_id, od_date, od_last_update,od_shipping_cost)
                VALUES ($id, NOW(), NOW(),$shippingCost)";
		$result = dbQuery($sql);
		
		// get the order id
		$orderId = dbInsertId();
		
		$_SESSION['order_id']   = $orderId;
		
		return $orderId;	
	
}
function saveOrder($orderId,$id)
{
	require_once 'cart-functions.php';
	$cartContent = getCartContent();
	$numItem     = count($cartContent);
	$payemail='';
	$sqlA = "SELECT * FROM tbl_temp_order WHERE od_id='$orderId'";
	$resultA = dbQuery($sqlA);
	$rowA=dbFetchAssoc($resultA);
	extract($rowA);	
	//if(checkEmail($od_payment_email)){
		$sqlB2 = "Select * FROM tbl_user_info WHERE user_id='$id'";
		$result=dbQuery($sqlB2);		
		$row = dbFetchAssoc($result);
		extract($row);
		$payemail=$user_payment_email;
		
		$sqlA1 = "INSERT INTO tbl_order(od_id, user_id, od_date, od_last_update, od_shipping_cost)
					VALUES ($od_id, $user_id, '$od_date', '$od_last_update',$od_shipping_cost)";
		dbQuery($sqlA1);
		
		
		$sqlB = "DELETE FROM tbl_temp_order WHERE od_id='$orderId'";
		dbQuery($sqlB);
		
		for ($i = 0; $i < $numItem; $i++) {
					$sql = "INSERT INTO tbl_order_item(od_id, pd_id, od_qty)
							VALUES ($orderId, {$cartContent[$i]['pd_id']}, {$cartContent[$i]['ct_qty']})";
					$result = dbQuery($sql);					
				}
				
		// update product stock
		for ($i = 0; $i < $numItem; $i++) {
			$sql = "UPDATE tbl_product 
					SET pd_qty = pd_qty - {$cartContent[$i]['ct_qty']}
					WHERE pd_id = {$cartContent[$i]['pd_id']}";
			$result = dbQuery($sql);					
		}
		
		// then remove the ordered items from cart
		for ($i = 0; $i < $numItem; $i++) {
			$sql = "DELETE FROM tbl_cart
					WHERE ct_id = {$cartContent[$i]['ct_id']}";
			$result = dbQuery($sql);					
		}
	//}
	return $payemail;
}
function quickBuySave($id,$userinfo)
	{
	$shopConfig = getShopConfig();
	$shippingCost  = $shopConfig['shippingCost'];
	extract($userinfo);
	
	
				
		$cartContent = getCartContent();
		$numItem     = count($cartContent);
		
		// save order & get order id
		$sql = "INSERT INTO tbl_temp_order(user_id, od_date, od_last_update, od_shipping_cost)
                VALUES ($id, NOW(), NOW(), $shippingCost)";
		$result = dbQuery($sql);
		
		// get the order id
		$orderId = dbInsertId();
		
		$_SESSION['order_id']   = $orderId;
		
		return $orderId;
	}
?>
Return current item: Uiga Cart