dblink = mysql_connect($this->hostname, $this->username, $this->password); mysql_select_db($this->database, $this->dblink); $this->cart_id = $cart_id; } function check_ord($cart_id) { $sql="SELECT ordercd FROM orders WHERE sessid='". $cart_id."'"; $ores=mysql_query($sql); if ($ores) { $row=mysql_fetch_row($ores); return $row[0]; } else { return true; } } function create_order($cart_id) { $ordervalid = $this->check_ord($cart_id); if ($ordervalid==true) { return null; } $query = "INSERT INTO orders (sessid, referrer, remoteip, remotehost, useragent, entrydate) VALUES ('$cart_id', '$referrer', 'remoteip', '$remotehost', '$useragent',NOW());"; mysql_query($query) or die (mysql_error()); return mysql_insert_id; } function check_item($product) { $query = "SELECT COUNT(skucd) as quantity FROM ".$this->cart_table. " WHERE sessid='".$this->cart_id."' AND skucd='$product' GROUP by skucd, sessid"; $result = mysql_query($query, $this->dblink) or die (mysql_error()); if(!$result) { return 0; } $numRows = mysql_num_rows($result); if($numRows != 0) { $row = mysql_fetch_object($result); return $row->quantity; } else { return 0; } } function delete_item($product) { $query = "DELETE FROM ".$this->cart_table." WHERE sessid='" . $this->cart_id."' AND skucd='$product' "; mysql_query($query, $this->dblink); mysql_query("UPDATE inventory SET webstatus ='checked' WHERE orsku='".$product."'", $this->dblink); } function clear_cart() { $sql="SELECT skucd FROM ".$this->cart_table." WHERE sessid='".$this->cart_id."' "; $thisres=mysql_query($sql); while ($res=mysql_fetch_array($thisres)) { $qry = "UPDATE inventory set webstatus='checked' where orsku='". $res['skucd']."'"; mysql_query($qry); } $query = "DELETE FROM ".$this->cart_table." WHERE sessid='".$this->cart_id."' "; mysql_query($query, $this->dblink); } function modify_quantity($product, $quantity) { if($quantity <= 0) return $this->delete_item($product); $query = "SELECT quantity FROM ".$this->inv_table. " WHERE product='$product'"; $result = mysql_query($query, $this->dblink); mysql_fetch_object($result); if($quantity > $result->quantity) return false; mysql_free_result($result); $query = "UPDATE ".$this->cart_table. " SET quantity='$quantity' WHERE session='".$this->cart_id."' "; $query .= "AND product='$product' "; mysql_query($query, $this->dblink); return true; } function get_contents() { $count = 0; $query = "SELECT ".$this->inv_table.".product," . $this->inv_table.".price," . $this->cart_table.".quantity,". $this->inv_table.".description, SUM(".$this->inv_table.".price*" . $this->cart_table.quantity .") as subtotal, SUM(subtotal) as total FROM ".$this->cart_table.",".$this->inv_table." WHERE session='".$this->cart_id."' AND ".$this->cart_table.".product = ". $this->inv_table.".product GROUP BY ". $this->cart_table.".product"; $result = mysql_query($query, $this->dblink); for($count = 0; array_push($contents, mysql_fetch_array($result)); $count++); $contents['items'] = $count; return $contents; } function view_cart($cart_id) { $i=0; $sql = "SELECT max( a.entrydate ) , b.skucd, a.webprice, c.skuname, CONCAT(c.height,' x ',c.width,' x ', c.length) as dims, c.weight as wgt FROM price a, order_cust b, inventory c WHERE a.skucd = b.skucd AND b.sessid='".$cart_id."' AND c.orsku=a.skucd GROUP BY a.skucd"; //print $sql; //$sql="SELECT skucd from order_cust where sessid='".$cart_id."'"; $res=mysql_query($sql); while ($row=mysql_fetch_array($res)) { $mycart[$i][0]=$row['skucd']; $mycart[$i][1]=$row['webprice']; $mycart[$i][2]=$row['skuname']; $mycart[$i][3]=$row['dims']; $mycart[$i][4]=$row['wgt']; $i++; } return $mycart; } function cart_total() { $query = "SELECT SUM(".$this->inv_table.".price*" . $this->cart_table.quantity .") as subtotal, SUM(subtotal) as total FROM ".$this->cart_table."," . $this->inv_table." WHERE session='".$this->cart_id."' AND ".$this->cart_table. ".product = " . $this->inv_table.".product " . " GROUP BY ".$this->cart_table.".product"; $result = mysql_query($query, $this->dblink); $row = mysql_fetch_row($result); return $row['total']; } function num_items() { $query = "SELECT COUNT(*) as count FROM " . $this->cart_table." WHERE session='" . $this->cart_id."' "; $result = mysql_query($query, $this->dblink); $row = mysql_fetch_array($result); return $row['count']; } function quant_items() { $quant = 0; $query = "SELECT SUM(quantity) as quantity FROM " . $this->cart_table." WHERE session='" . $this->cart_id."' "; $result = mysql_query($query, $this->dblink); $row = mysql_fetch_array($result); return $row['quantity']; } } // End of object ?>