Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

What does this error message mean?

I'm new to OOP and it's flat kicking the stew out of me. Things that I know how to do are now having to be relearned, but that's OK. That's how you get better.

OK, the problem is I've got to knock this out today and rather than wasting time puttering around, I'm just going to ask the ninjas so I can expedite the learning curve.

I've just tried to write my first function. The code is below and I get the following error message:

Fatal error: Call to a member function query_first() on a non-object in /var/www/vhosts/kolcrafttesting.com/httpdocs/includes/classes/cart.class.php on line 124

Here's my code:

      public function insertCartorder(&$conn){
            //first thing, establish new id for the new order
            $count_order_sql = "SELECT id  FROM tblorderdetails ORDER by id DESC LIMIT 1";
            $count_data = $count_order->query_first($count_order_sql);
            $new_id = $count_data['id'] + 1;
            echo $new_id;
                  
            
      }

I am a pig on roller skates so please forgive whatever represents a blatant and altogether obvious flaw. What does the error mean and how do I fix it?
SOLUTION
Avatar of Peter Hart
Peter Hart
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry not a contructor but a variable out of scope...
Avatar of Bruce Gust

ASKER

Thanks for weighing in, chilternPC. The entire cart.class.php code is attached.

Thanks!
<?php

class Cart {
	//TODO  make all vars private 


	var $cart_items; //= array();
	## Personal Details
    var $firstName;
    var $lastName;
    var $address1;
    var $city;
    var $state;
    var $zip;
    var $phone;
    var $email;
	## Shipping Details
    var $shipping_location;
    var $shipfirstName;
    var $shiplastName;
    var $shipaddress1;
    var $shipcity;
   	var $shipstate;
    var $shipzip;
    var $shipphone;
    var $shipemail;
	## Card Details
	var $cctype;
    var $cardnumber;
    var $expMonth;
    var $expYear;
    var $cardfirstname;
    var $cardlastname;
	
	function __construct(){
		//$_SESSION['cart'] = $cart;

	}

	public function writeShoppingCart() {
		if (!$this->cart_items) {
			return 'You have no items in your shopping cart<br />';
		} else {
			// Parse the cart session variable
			#	print_r($cart);
			$items = explode(',',$this->cart_items);
			$s = (count($items) > 1) ? 's':'';
			return 'You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a><br />';
		}
	}

	public function showCart(&$conn) {
		#if(is_object($_SESSION['cart'])) {
		#	$cart = $_SESSION['cart'];
		#}
		
		
		if ($this->cart_items) {
			$items = explode(',',$this->cart_items);
			#echo $items;
			$contents = array();
			foreach ($items as $item) {
				$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
			}
			$output[] = '<form action="cart.php?a=update" method="post" id="cart">';
			$output[] = '<table cellspacing="0" cellpadding="5" width="660">';
			$output[] = '<tr id="productrowtitle"><td align="center">Item:</td><td align="center">Price:</td><td align="center">Qty:</td><td align="center">Price X Qty</td><td align="center">Remove</td></tr>';
			#print_r($contents);
			foreach ($contents as $id=>$qty) {
				$sql = 'SELECT tblreplacementparts.*, tblreplacementproductparts.id, tblreplacementproductparts.replacementProductID, tblreplacementproductparts.price FROM tblreplacementproductparts LEFT JOIN tblreplacementparts ON tblreplacementparts.id = tblreplacementproductparts.partID WHERE partID = '.$id;
				#echo $sql;
				/*[id] => 19 [replacementProductID] => 6 [partID] => 12 [price] => 12 [quantity] => 0 [dateCreated] => 2006-08-07 15:40:51 [dateUpdated] => [userID] => 3 )partName] => Potty Base [partNum] => K21001-RED2 [partDesc*/
				$results= $conn->query_first($sql);
				#print_r($results);
				$output[] = '<tr id="productrowproduct">';
				$output[] = '<td><img src="'.BASE_HREF.'images/replacementparts/'.$results['partImage'].'" width="100" border="0"><br />'.$results['partName'].'</td>';
				$output[] = '<td>$'.$results['price'].'</td>';
				$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
				$output[] = '<td align="center">$'.($results['price'] * $qty).'</td>';
				$output[] = '<td><a href="cart.php?a=delete&partid='.$id.'" class="r">Remove</a></td>';
				$total += $results['price'] * $qty;
				$output[] = '</tr>';

			}
			$output[] = '<tr id="productrowtitle"><td colspan="3" align="right">Grand total</td><td colspan="2" align="left">$'.$total.'</td></tr>';
			$output[] = '</table>';
			$output[] = '<div><button type="submit">Update cart</button> <a href="'.BASE_HREF.'checkout.php"><img src="'.BASE_HREF.'images/buttons/btn-checkout.gif" border="0"></a></div>';
			$output[] = '</form>';
		} else {
			$output[] = '<p>You shopping cart is empty.</p>';
		}
		return join('',$output);
	}

	public function returnCartProducts(&$conn){
		
		$cart = $_SESSION['cart'];
		#if ($cart) {f
			$items = explode(',',$this->cart_items);
			#echo $items;
			$contents = array();
			foreach ($items as $item) {
				$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
			}
			foreach ($contents as $id=>$qty) {
				$sql = 'SELECT tblreplacementparts.*, tblreplacementproductparts.id, tblreplacementproductparts.replacementProductID, tblreplacementproductparts.price FROM tblreplacementproductparts LEFT JOIN tblreplacementparts ON tblreplacementparts.id = tblreplacementproductparts.partID WHERE partID = '.$id;
				$results= $conn->query_first($sql);
				#print_r($contents);
				 $cartProducts .= '<tr height="20"><td>'.$results['partNum'].'</td>
							<td width="100">$'.sprintf('%01.2f',$results['price']).'</td>
							<td width="100">'.$qty.'</td>
							<td align="center" width="100">$'.sprintf('%01.2f', $results['price'] * $qty).'</td></tr>';
			}
			
		#}
		
		return $cartProducts;
		
	}
	
	public function insertCartorder(&$conn){
		//first thing, establish new id for the new order
		$count_order_sql = "SELECT id  FROM tblorderdetails ORDER by id DESC LIMIT 1";
		$count_data = $count_order->query_first($count_order_sql);
		$new_id = $count_data['id'] + 1;
		echo $new_id;
			
		
	}
	

	public function returnCartTotalPrice(&$conn, $taxCharge="", $shipping=false){
		#print_r($conn);
	#	$cart = $_SESSION['cart'];
		#var_dump($cart);
		#if ($cart) {
			$items = explode(',',$this->cart_items);
			#echo $items;
			$contents = array();
			foreach ($items as $item) {
				// ADD UP CART CONTENT PRICES
				$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
				$totalPrice = 0;
				foreach ($contents as $id=>$qty) {
					$sql = 'SELECT tblreplacementparts.*, tblreplacementproductparts.id, tblreplacementproductparts.replacementProductID, tblreplacementproductparts.price FROM tblreplacementproductparts LEFT JOIN tblreplacementparts ON tblreplacementparts.id = tblreplacementproductparts.partID WHERE partID = '.$id;
					$results= $conn->query_first($sql);
					$totalPrice = $totalPrice + ($results['price'] * $qty);
				}
			}
		#}
		// APPLY TAXES
		if($taxCharge) {
			$totalPrice = $totalPrice + $taxCharge;
		}
		// APPLY SHIPPING
		if($shipping) { 
			$price = $totalPrice+$shipping;
			return $price;
		} else { 
			return $totalPrice;
		}	
	}
	
	// DETERMINE THE TOTAL WEIGHT OF CART PRODUCTS.
	public function cartItemWeight(&$conn) {
		#print_r($this);
		#die();
		#echo "cartWeight";
		#$cart = $_SESSION['cart'];
				/*
		if($this->cart_items) {
			$this->cart_items = $this->cart_items.','.$item;
		} else {
			$this->cart_items = $item;
		}*/
		#if(is_object($_SESSION['cart'])) {
			#$cart = $_SESSION['cart'];
		#}
		#var_dump($cart);
		$totalWeight == 0; // set weight to nothing.
		if ($this->cart_items) {
			$items = explode(',',$this->cart_items);
		
			$contents = array();
			foreach ($items as $item) {
				$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
			}
			#echo "|".$contents[$item]."|";
			foreach ($contents as $id=>$qty) {
				#echo "this is my id ".$id."<br />";
				#echo "this is my qty ".$qty."<br />";
				$sql = 'SELECT tblreplacementparts.*, tblreplacementproductparts.id, tblreplacementproductparts.replacementProductID, tblreplacementproductparts.price FROM tblreplacementproductparts LEFT JOIN tblreplacementparts ON tblreplacementparts.id = tblreplacementproductparts.partID WHERE partID = '.$id;
				#echo $sql;
				$results = $conn->query_first($sql);
				$totalWeight .= $totalWeight + $results['weight'] * $qty;
				//echo "my weight".$results['weight'];
			}
		}
		return $totalWeight;
		
	}
	
	// BASED ON SHIPPING RECIPIENT STATE - NOT BILLING ADDRESS
	static function getOrderTaxes(&$conn, $price="", $shipping="", $zip="", $state="") {
		$sql = "SELECT stateSalesTax FROM tbltaxrates WHERE zip='$_POST[zip]' AND state='$_POST[state]'";
		$totalPrice = $price + $shipping;
		$taxRate = $conn->query_first($sql);
		$taxCharge = $totalPrice * $taxRate['stateSalesTax'];
		#print_r($taxRate);
		$formattedTaxCharge = sprintf('%01.2f', $taxCharge);
		return $formattedTaxCharge;
	}
	
	public function calculateShipping(&$conn, $totalWeight){
		$sql = "SELECT * FROM tblshippingweights WHERE shippingWeight >= $totalWeight LIMIT 1";	
		#echo $sql;
		$shiprate = $conn->query_first($sql);
		return sprintf("%01.2f", $shiprate['shippingPrice']);
	}
	
	static function ValidateCard($cardArray) {
		if($cardArray) {
				echo "Put Authorize.net stuff here";
		}
		return "validated";
	}
	
	static function getOrderProducts(&$conn, $orderID){
		$orderID = $orderID;
		$sql = "SELECT tblorders.*, tblorderdetails.id, tblorderdetails.orderID, tblorderdetails.item, tblorderdetails.price, tblorderdetails.quantity, tblorderdetails.partID, tblorderdetails.productID, tblorderdetails.isPart, tblorderdetails.manufactureMonth, tblorderdetails.manufactureYear, tblorderdetails.purchaseMonth, tblorderdetails.purchaseYear, tblorderdetails.isBackOrdered
		FROM tblorders
		LEFT JOIN tblorderdetails ON tblorderdetails.orderID = tblorders.id
		WHERE tblorders.id='$orderID'";
		
		$returned_products = $conn->fetch_all_array($sql);
		//print_r($returned_products);
		$orderRows = "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
		 <tr style=\"background-color:#ccc;\">
			<td><b>OrderID</b></td>
			<td><b>PartID</b></td>
			<td><b>ItemNum</b></td>
			<td align=\"left\"><b>Price</b></td>
			<td><b>$ Sum</b></td>
			<td align=\"center\"><b>Quantity</b></td>
			<td><b>DateCreated</b></td>
	    </tr>";
		$totalPrice = 0;
		foreach($returned_products as $orderValue) {
			$totalPrice .= $totalPrice + $orderValue['price'];
			$price_sum = $orderValue['price']*$orderValue['quantity'];
			$orderRows .= "<tr>
					<td>".$orderValue['orderID']."</td>
					<td>".$orderValue['partID']."</td>
					<td>".$orderValue['item']."</td>
					<td align=\"left\">$".$orderValue['price']."</td>
					<td align=\"center\">".$orderValue['quantity']."</td>
					<td>".$price_sum."</td>
					<td>".$orderValue['dateCreated']."</td>
				</tr>";
		}
		$orderRows .="<tr>
				<td></td>
				<td></td>
				<td><b>Total Product Price</b>:</td>
				<td>$".$totalPrice."</td>
				<td colspan=\"3\">&nbsp;</td>
			</tr></table>";
		
		return $orderRows;
	}
	
	static function getOrderPayment(&$conn, $orderID) {
		$orderID = $orderID;
		$sql = "SELECT tblorderpayment.* 
		FROM tblorderpayment
		WHERE tblorderpayment.orderID='$orderID'";
		$data = $conn->query_first($sql);
		#print_r($data);
		$nameOnCard = $data['nameOnCard'];
		// FIX CC NUMBER FOR DISPLAY.
		$last4digits = substr($data['creditCardNum'], -4);  // ESCAPE CREDIT CARD FROM PUBLIC DISPLAY.
		$creditCardNum = $last4digits;
		$creditCardType = $data['creditCardType'];
		$expMonth = $data['expMonth'];
		$expYear = $data['expYear'];
		
		$formatted_payment = "<table border='0' cellpadding'0' cellspacing='0' width='100%'>
			<tr style=\"background-color:#ccc;\">
				<td colspan='4'><b>Payment Details</b></td>
			</tr>
			<tr style=\"background-color:#ccc;\">
				<td valign=\"top\"><b>Name on Card</b></td>
				<td valign=\"top\"><b>Credit Card #</b><br /><span style=\"font-size:8pt;\">(last 4)</span></td>
				<td valign=\"top\"><b>Credit Card Type</b></td>
				<td valign=\"top\"><b>Exp Date</b></td>			
			</tr>
			<tr>
				<td>".$nameOnCard."</td>
				<td>".$creditCardNum."</td>
				<td>".$creditCardType."</td>
				<td>".$expMonth." / ".$expYear."</td>
			</tr>
		</table>";
		#echo $formatted_payment;
		return $formatted_payment;
	}

	static function getOrderStatus(&$conn, $orderID) {
		$sql = "SELECT tblorderstatuses.orderStatus FROM tblorderstatuses
		LEFT JOIN tblorders ON tblorders.statusID = tblorderstatuses.id
		WHERE tblorders.id = '$orderID'";
		$status_list = $conn->query_first($sql);
		$status = $status_list['orderStatus'];
		return $status;
	}
	
	static function getOrderAddress(&$conn, $orderID){
		$sql = "SELECT * 
		FROM tblorderaddresses
		WHERE orderID = '$orderID'";
		$orderAddress = $conn->query_first($sql);
		// BILLING
		$bFullName = $orderAddress['bFullname'];
		$bFirstName = $orderAddress['bFirstname'];
		$bLastName = $orderAddress['bLastname'];
		$bAddress1 = $orderAddress['bAddress1'];
		if($orderAddress['bAddress2']) {
			$bAddress2 = $orderAddress['bAddress2']."<br />";
		}
		$bCity = $orderAddress['bCity'];
		$bState = $orderAddress['bState'];
		$bZip = $orderAddress['bZip'];
		$bPhone = $orderAddress['bPhone'];
		$bEmail = $orderAddress['bEmail'];
		// SHIPPING
		$sFullName = $orderAddress['sFullname'];
		$sFirstName = $orderAddress['sFirstname'];
		$sLastName = $orderAddress['sLastname'];
		$sAddress1 = $orderAddress['sAddress1'];
		if($orderAddress['sAddress2']) {
			$sAddress2 = $orderAddress['sAddress2']."<br />";
		}
		$sCity = $orderAddress['sCity'];
		$sState = $orderAddress['sState'];
		$sZip = $orderAddress['sZip'];
		$sPhone = $orderAddress['sPhone'];
		$sEmail = $orderAddress['sEmail'];
		// date created
		$dateCreated = $orderAddress['dateCreated'];
		
		$formatOrderAddress = "<table width=\"100%\">
			<tr style=\"background-color:#ccc;\">
				<td><b>Billing Address</b></td>
				<td><b>Shipping Address</b></td>
			</tr>
			<tr>
				<td>
					".$bFullName."<br />
					".$bAddress1."<br />
					".$bAddress2."
					".$bCity."<br />
					".$bState."<br />
					".$bZip."<br />
					".$bPhone."<br />
					".$bEmail."<br />
				</td>
				<td>
					".$sFullName."<br />
					".$sAddress1."<br />
					".$sAddress2."
					".$sCity."<br />
					".$sState."<br />
					".$sZip."<br />
					".$sPhone."<br />
					".$sEmail."<br />
				</td>
			</tr>
		</table>";
		// send back fromatted table.
		return $formatOrderAddress;
	}
	static public function orderPriceSummary(&$conn, $orderID){
		$sql = "SELECT price, quantity FROM tblorderdetails WHERE orderID = '$orderID'";
		#echo $sql;
		$priceSummary = $conn->fetch_all_array($sql);
		$TotalPrice == 0; // start off with 0.
		foreach($priceSummary as $price_sum) {
			#print_r($price_sum);
			$TotalPrice = $TotalPrice + ($price_sum['price'] * $price_sum['quantity']);
			#echo $TotalPrice;
		}
		return $TotalPrice;
	}
	
	static public function orderWeight($conn, $orderID) {
		$sql = "SELECT weightTotal FROM tblorders WHERE id = '$orderID'";
		$getWeight=$conn->query_first($sql);
		return $getWeight['weightTotal']." lbs.";
	}
	static public function shippingTotal($conn, $orderID) {
		$sql = "SELECT shippingTotal FROM tblorders WHERE id = '$orderID'";
		$getShippingTotal=$conn->query_first($sql);
		$getShippingTotal = sprintf('%01.2f', $getShippingTotal['shippingTotal']);
		return $getShippingTotal;
	}
	
	static public function showMonths($selectedMonth="") {
		$months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novemeber", "December");
		$monthCount = "1"; // starts on January's value.
		$list ="Month: <select name=\"expMonth\">";
		foreach($months as $monthname) {
			if($monthCount == $selectedMonth) { $selected = "SELECTED"; } else { $selected = "";}
		   $list .= "<option value=\"".$monthCount."\" ".$selected.">".$monthname."</option>";
		   $monthCount++; // increment to next month.
		}
		$list .="</select>";
		return $list;
	}
	
	static public function showMonth($selectedMonth="") {
		$months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novemeber", "December");
		foreach($months as $monthname) {
			if($monthCount == $selectedMonth) { 
				 $showMonth = $monthname;
			}
		}
		return $showMonth;
	}
	static public function showYears($selectedYear=""){
		#print_r($selectedYear);
		$thisYear = date(Y);
		$endYear = $thisYear+10;
		//var_dump($thisYear);
		// 2009 - 2019
		for ($i = $thisYear; $i <= $endYear; ++$i) {
        	$years[] = $i;
		}
		
		$yearList ="Year: <select name=\"expYear\">";
		foreach($years as $val) {
			if($selectedYear == $val) { $selected ="SELECTED";} else { $selected ="";}
			$yearList .= "<option $selected>".$val."</option>";
		}
		$yearList .="</select>";
		//var_dump($yearList);
		return $yearList;
		
	}
	## set shopping cart variables from POST.
	public function setSessionVars($_POST){
		#echo "SETTING SESSION VARIABLES<br />";
		#print_r($_POST);
		#echo "<pre>"; print_r($_SESSION);echo "</pre>";
		//print_r($_SESSION['cart']);
		if($_POST['firstName']) {
			$_SESSION['cart']->firstName = $_POST['firstName'];
			$firstName = $_SESSION['cart']->firstName;
		}
		if($_POST['lastName']) {
			$_SESSION['cart']->lastName = $_POST['lastName'];
			#$lastName = mysql_real_escape_string($_POST['lastName']);
			#$_SESSION['lastName'] = $lastName;
		}
		if($_POST['address1']) {
			$_SESSION['cart']->address1 = $_POST['address1'];
			#$address1 = mysql_real_escape_string($_POST['address1']);
			#$_SESSION['address1'] = $address1;
		}
		if($_POST['address2']) {
			$_SESSION['cart']->address2 = $_POST['address2'];
			#$address2 = mysql_real_escape_string($_POST['address2']); 
			#$_SESSION['address2'] = $address2;
		}
		if($_POST['city']) {
			$_SESSION['cart']->city = $_POST['city'];
			#$city = mysql_real_escape_string($_POST['city']);
			#$_SESSION['city'] = $city;
		}
		if($_POST['state']) {
			$_SESSION['cart']->state = $_POST['state'];
			#$state = mysql_real_escape_string($_POST['state']);
			#$_SESSION['state'] = $state;
		}
		if($_POST['zip']) {
			$_SESSION['cart']->zip = $_POST['zip'];
			#$zip = mysql_real_escape_string($_POST['zip']);
			#$_SESSION['zip'] = $zip;
		}
		if($_POST['phone']) {
			$_SESSION['cart']->phone = $_POST['phone'];
			#$phone = mysql_real_escape_string($_POST['phone']);
			#$_SESSION['phone'] = $phone;
		}
		if($_POST['email']) {
			$_SESSION['cart']->email = $_POST['email'];
			#$email = mysql_real_escape_string($_POST['email']);
			#$_SESSION['email'] = $email;
		}
		if($_POST['shipping_location']) {
			$_SESSION['cart']->shipping_location = $_POST['shipping_location'];
			#$shipping_location =mysql_real_escape_string( $_POST['shipping_location']);
			#$_SESSION['shipping_location'] = $shipping_location;
		}
		if($_POST['shipfirstName']) {
			$_SESSION['cart']->shipfirstName = $_POST['shipfirstName'];
			#$shipfirstName = mysql_real_escape_string($_POST['shipfirstName']);
			#$_SESSION['shipfirstName'] = $shipfirstName;
		}
		if($_POST['shiplastName']) {
			$_SESSION['cart']->shiplastName = $_POST['shiplastName'];
			#$shiplastName = mysql_real_escape_string($_POST['shiplastName']);
			#$_SESSION['shiplastName'] = $shiplastName;
		}
		if($_POST['shipaddress1']) {
			$_SESSION['cart']->shipaddress1 = $_POST['shipaddress1'];
			#$shipaddress1 = mysql_real_escape_string($_POST['shipaddress1']);
			#$_SESSION['shipaddress1'] = $shipaddress1;
		}
		if($_POST['shipaddress2']) {
			$_SESSION['cart']->shipaddress2 = $_POST['shipaddress2'];
			#$shipaddress2 = mysql_real_escape_string($_POST['shipaddress2']);
			#$_SESSION['shipaddress2'] = $shipaddress2;
		}
		if($_POST['shipcity']) {
			$_SESSION['cart']->shipcity = $_POST['shipcity'];
			#$shipcity = mysql_real_escape_string($_POST['shipcity']); 
			#$_SESSION['shipcity'] = $shipcity;
		}
		if($_POST['shipstate']) {
			$_SESSION['cart']->shipstate = $_POST['shipstate'];
			#$shipstate = mysql_real_escape_string($_POST['shipstate']);
			#$_SESSION['shipstate'] = $shipstate;
		}
		if($_POST['shipzip']) {
			$_SESSION['cart']->shipzip = $_POST['shipzip'];
			#$shipzip = mysql_real_escape_string($_POST['shipzip']);
			#$_SESSION['shipzip'] = $shipzip;
		}
		if($_POST['shipphone']) {
			$_SESSION['cart']->shipphone = $_POST['shipphone'];
			#$shipphone = mysql_real_escape_string($_POST['shipphone']);
			#$_SESSION['shipphone'] = $shipphone;
		}
		if($_POST['shipemail']) {
			$_SESSION['cart']->shipemail = $_POST['shipemail'];
			#$shipemail = mysql_real_escape_string($_POST['shipemail']); 
			#$_SESSION['shipemail'] = $shipemail;
		}
		if($_POST['cctype']){
			$_SESSION['cart']->cctype = $_POST['cctype'];
			#$cctype =  mysql_real_escape_string($_POST['cctype']);
			#$_SESSION['cctype'] = $cctype;
		}
		if($_POST['cardnumber']){
			$_SESSION['cart']->cardnumber = $_POST['cardnumber'];
			#$cardnumber=  mysql_real_escape_string($_POST['cardnumber']);
			#$_SESSION['cardnumber'] = $cardnumber;
		}
		if($_POST['cardfirstname']){
			$_SESSION['cart']->cardfirstname= $_POST['cardfirstname'];
			#$cardfirstname = mysql_real_escape_string($_POST['cardfirstname']);
			#$_SESSION['cardfirstname'] = $cardfirstname;
		}
		if($_POST['cardlastname']){
			$_SESSION['cart']->cardlastname = $_POST['cardlastname'];
			#$cardlastname = mysql_real_escape_string($_POST['cardlastname']);
			#$_SESSION['cardlastname'] = $cardlastname;
		}		  
		if($_POST['expMonth']){
			$_SESSION['cart']->expMonth = $_POST['expMonth'];
			#$expMonth =  mysql_real_escape_string($_POST['expMonth']);
			#$_SESSION['expMonth'] = $expMonth;
		}
		if($_POST['expYear']){
			$_SESSION['cart']->expYear = $_POST['expYear'];
			#$expYear =  mysql_real_escape_string($_POST['expYear']);
			#$_SESSION['expYear'] = $expYear;
		}
		if($_POST['storename']){
			$_SESSION['cart']->storename = $_POST['storename'];
			#$storename =  mysql_real_escape_string($_POST['storename']);
			#$_SESSION['storename'] = $storename;
		}
		if($_POST['chargetotal']){
			$_SESSION['cart']->chargetotal = $_POST['chargetotal'];
			#$chargetotal =  mysql_real_escape_string($_POST['chargetotal']);
			#$_SESSION['chargetotal'] = $chargetotal;
		}
		
		if($_POST['cardfirstname']){
			$_SESSION['cart']->cardfirstname = $_POST['cardfirstname'];
			#$cardfirstname = mysql_real_escape_string($_POST['cardfirstname']);
			#$_SESSION['cardfirstname'] = $cardfirstname;
		}
		if($_POST['cardlastname']){
			$_SESSION['cart']->cardlastname = $_POST['cardlastname'];
			#$cardlastname = mysql_real_escape_string($_POST['cardlastname']);
			#$_SESSION['cardlastname'] = $cardlastname;
		}
		if($_POST['cardnumber']){
			$_SESSION['cart']->cardnumber = $_POST['cardnumber'];
			#$cardnumber = mysql_real_escape_string($_POST['cardnumber']);
			#$_SESSION['cardnumber'] = $cardnumber;			
		}
		if($_POST['cctype']){
			$_SESSION['cart']->cctype = $_POST['cctype'];
			#$cctype = mysql_real_escape_string($_POST['cctype']);
			#$_SESSION['cctype'] = $cctype;
		}
		if($_POST['expireMonth']){
			$_SESSION['cart']->expireMonth = $_POST['expireMonth'];
			#$expireMonth = mysql_real_escape_string($_POST['expireMonth']);
			#$_SESSION['expireMonth'] = $expireMonth;			
		}
		if($_POST['expireYear']){
			$_SESSION['cart']->expireYear = $_POST['expireYear'];
			#$expireYear = mysql_real_escape_string($_POST['expireYear']);
			#$_SESSION['expireYear'] = $expireYear;
		}
		if($_POST['cvm']){
			$_SESSION['cart']->cvm = $_POST['cvm'];
			#$cvm = mysql_real_escape_string($_POST['cvm']);
			#$_SESSION['cvm'] = $cvm;
		}
		#$_SESSION['cart'] = $this;
		#print_r($_SESSION['cart']);
		#$_SESSION['cart'] = $this;
		#echo "<pre>";print_r($_SESSION['cart']);echo "</pre>";
	}
	## cartSessionData
	public function formatSessionData($conn){
		//$_SESSION();
		#echo "trying to run formatSessionData";
		$total = $this->returnCartTotalPrice($conn);
		$cartWeight = $this->cartItemWeight($conn);
		//print_r($cartWeight);
		$shippingPrice = $this->calculateShipping($conn, $cartWeight);
		$TaxToCharge = $this->getOrderTaxes($conn, $total, $shippingPrice, $_SESSION['shipzip'], $_SESSION['shipstate']);
		#print_r($TaxToCharge);
		$totalPrice = $this->returnCartTotalPrice($conn, $shippingPrice, $TaxToCharge);
		
		#$_SESSION[''];
		$send = array(
			//'C'            => base64_encode("checkout.processorder.viewrecipt"),
			'storename'    => '',
			'mode'         => 'PayPlus',
			'subtotal'     => $total,
			'shipping'     => $shippingPrice,
			'tax'    	   => $TaxToCharge,
			'chargetotal'  => $totalPrice,
			//'taxexempt'    => 'True',
			'txnorg'       => 'eci',
			'txntype'      => 'sale',
			'debug'		   => 'true',
			//'oid'        => not getting passed because it's a huge PITA as order IDs are an autoincrement field in the DB,
			'responseURL'  => 'https://www.kolcraft.com/thankyou.php',
			'cardnumber'   => $_SESSION['cart']->cardnumber,
			'expmonth'     => $_SESSION['cart']->expMonth,
			'expyear'      => $_SESSION['cart']->expYear,
			'cvm'          => $_SESSION['cart']->cvm,
			'bname'        => $_SESSION['cart']->cardfirstname.', '.$_SESSION['cart']->cardlastname,
			'baddr1'       => $_SESSION['cart']->address1,
			'bcity'        => $_SESSION['cart']->city,
			'bstate'	   => $_SESSION['cart']->state,
			//'bstate2'    => only for States/Provinces in other countries,
			'bzip'         => $_SESSION['cart']->zip,
			'country'      => 'US',
			'baddr2'		=> $_SESSION['cart']->address2,
			'email'			=> $_SESSION['cart']->email,
			'oid'			=> '', // this is the order id.. LAST_INSERT_ID + 1 from orders table...
			'sname'			=> $_SESSION['cart']->shipfirstName.', '.$_SESSION['cart']->shiplastName,
			'saddr1'		=> $_SESSION['cart']->shipaddress1,
			'saddr2'		=> $_SESSION['cart']->shipaddress2,
			'scity'			=> $_SESSION['cart']->shipcity,
			'sstate'		=> $_SESSION['cart']->shipstate,
			'szip'			=> $_SESSION['cart']->shipzip,
			'scountry'		=> 'US',
			'phone'			=> $_SESSION['cart']->phone
			//'fax'			=> ''
			
		);
		#print_r($send);
		return $send;
		
	}
	
	public function addItem($item){
		if($this->cart_items) {
			$this->cart_items = $this->cart_items.','.$item;
		} else {
			$this->cart_items = $item;
		}
		
		$_SESSION['cart'] = $this;
	} // end addItem
	
	public function updateItem($_POST){
		#echo "running update";
		#print_r($_POST);
		foreach ($_POST as $key=>$value) {
					if (stristr($key,'qty')) {
						$id = str_replace('qty','',$key);
						$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$this->cart_items);
						$newcart = '';
						
						foreach ($items as $item) {
							//echo $item."<br >";
							if ($id != $item) {
								if ($newcart != '') {
									$newcart .= ','.$item;
								} else {
									$newcart = $item;
								}
							}
						} // for
						for ($i=1;$i<=$value;$i++) {
							if ($newcart != '') {
								$newcart .= ','.$id;
							} else {
								$newcart = $id;
							}
						} // for
					} // if
				} // foreach
				#echo "newcart".$newcart;
				
				$this->cart_items = $newcart;
				
				$_SESSION['cart'] = $this;
			//	print_r($_SESSION['cart']);
				#$cart = $_SESSION['cart'];
				//$cart = $_SESSION['cart'];
	} // end addItem
	
	public function deleteItem($partID){
			#	echo "deleting". $partID;
			$items = explode(',',$this->cart_items);
				$newcart = '';
				foreach ($items as $item) {
					#echo $item;
					if ($partID != $item) {
						if ($newcart != '') {
							$newcart .= ','.$item;
						} else {
							$newcart = $item;
						}
					}
					#echo '<pre>';print_r($newcart);echo '</pre>';
				}
				$_SESSION["cart"]->cart_items = $newcart;
				$cart = $_SESSION['cart'];
				//$_SESSION['cart'] = $this;
				
	}
	/*
	public function InitilizeCheckout(){
		
	}
	*/
	
	public function showStateSelectList($selectedState="", $formName="state"){
		$stateList = "<select name=\"".$formName."\" id=\"".$formName."\" class=\"required\">";
		$state_list = array(
			'AL'=>"Alabama",
			'AK'=>"Alaska", 
			'AZ'=>"Arizona", 
			'AR'=>"Arkansas", 
			'CA'=>"California", 
			'CO'=>"Colorado", 
			'CT'=>"Connecticut", 
			'DE'=>"Delaware", 
			'DC'=>"District Of Columbia", 
			'FL'=>"Florida", 
			'GA'=>"Georgia", 
			'HI'=>"Hawaii", 
			'ID'=>"Idaho", 
			'IL'=>"Illinois", 
			'IN'=>"Indiana", 
			'IA'=>"Iowa", 
			'KS'=>"Kansas", 
			'KY'=>"Kentucky", 
			'LA'=>"Louisiana", 
			'ME'=>"Maine", 
			'MD'=>"Maryland", 
			'MA'=>"Massachusetts", 
			'MI'=>"Michigan", 
			'MN'=>"Minnesota", 
			'MS'=>"Mississippi", 
			'MO'=>"Missouri", 
			'MT'=>"Montana",
			'NE'=>"Nebraska",
			'NV'=>"Nevada",
			'NH'=>"New Hampshire",
			'NJ'=>"New Jersey",
			'NM'=>"New Mexico",
			'NY'=>"New York",
			'NC'=>"North Carolina",
			'ND'=>"North Dakota",
			'OH'=>"Ohio", 
			'OK'=>"Oklahoma", 
			'OR'=>"Oregon", 
			'PA'=>"Pennsylvania", 
			'RI'=>"Rhode Island", 
			'SC'=>"South Carolina", 
			'SD'=>"South Dakota",
			'TN'=>"Tennessee", 
			'TX'=>"Texas", 
			'UT'=>"Utah", 
			'VT'=>"Vermont", 
			'VA'=>"Virginia", 
			'WA'=>"Washington", 
			'WV'=>"West Virginia", 
			'WI'=>"Wisconsin", 
			'WY'=>"Wyoming");
		#	print_r($state_list);
		if($selectedState == "") {
			$stateList .= "<option value=\"\" selected>Select</option>";
		}
		foreach ($state_list as $abbr => $stateName){
			if(!$selectedState == "" && $selectedState == $abbr) { 
				$selected = "SELECTED";
			} else {
				$selected = "";
			}	
			$stateList .= "<option value=\"".$abbr."\" ".$selected.">".$stateName."</option>";			
		}
		return $stateList;
	}
	public function validateVars() {
		// s that all the fields have been filled out.
		if($this->firstName && $this->lastName && $this->address1 && $this->city && $this->state && $this->zip && $this->phone && $this->email && $this->shipfirstName && $this->shiplastName && $this->shipaddress1 && $this->shipcity && $this->shipstate && $this->shipzip && $this->shipphone && $this->shipemail) {
			$validated = true;
		} else {
			$validated = false;
		}
		return $validated;
	}
	
	public function validateCC() {
		if($this->cctype && $this->cardnumber &&  $this->expMonth &&  $this->expYear && $this->cardfirstname && $this->cardlastname && $this->cvm) {
			// DO INDIVIDUAL FIELD CHECK.
			$validated = true;
		} else {
			$validated = false;
		}
		return $validated;
	}
	
	public function maskCC ( $str, $start = 0, $length = null ) {
        $mask = preg_replace ( "/\S/", "*", $str );
        if ( is_null ( $length )) {
            $mask = substr ( $mask, $start );
            $str = substr_replace ( $str, $mask, $start );
        } else {
            $mask = substr ( $mask, $start, $length );
            $str = substr_replace ( $str, $mask, $start, $length );
        }
        return $str;
    }
	
}
?>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial