Jump to content

Fatal Error Problem


keith_Thornton

Recommended Posts

Hello,

 

I am looking for help with an e-commerce site.

 

After uploading my site and discontinuing TEST mode, I am getting an error message that reads:

 

Fatal error: Cannot redeclare getuniqueorderid() (previously declared in /home/content/l/l/o/CWIncProcessOrder.php:29) in /home/content/l/l/o/CWIncProcessOrder.php on line 60.

 

 

The error occurs directly after I place the order for the product.  Initially I thought there was a duplicate file somewhere but that does not seem to be the case.

 

Any insight is welcome.

 

KT

Link to comment
Share on other sites

You have included the file containing the function getuniqueorderid() more than once or you have 2 functions with that name. This is not allowed. The error message is telling you where the function is declared.

Line 29 reads:

 

function getUniqueOrderId($size=20, $formatString = '', $prefix="cw") {

 

Line 60 reads:

 

if($rsCWGetId_recordCount > 0) {

return getUniqueOrderId($size);

}else{

return $orderid;

}

}

 

So the problem, re-declaring unique order id, arises when there is an attempt to return that function on line 60.  Is this accurate? 

Link to comment
Share on other sites

The only way for us to help with what your code is doing is if you post your code. Just posting a couple of lines out of context does not show what is happening that would cause the error. Post your CWIncProcessOrder.php file and if this file is being include by another file, post the code that is including it, all the way up to the main script that is running.

Link to comment
Share on other sites

The only way for us to help with what your code is doing is if you post your code. Just posting a couple of lines out of context does not show what is happening that would cause the error. Post your CWIncProcessOrder.php file and if this file is being include by another file, post the code that is including it, all the way up to the main script that is running.

 

<?php
/* 
================================================================
Application Info: 
Cartweaver© 2002 - 2007, All Rights Reserved.
Developer Info: 
Application Dynamics Inc.
1560 NE 10th
East Wenatchee, WA 98802
Support Info: http://www.cartweaver.com/go/phphelp

Cartweaver Version: 3.0.6  -  Date: 12/2/2007

================================================================
Name: CWIncProcessOrder.php
Description: 
The Process Order include file adds the user's order to the
database. All data is validated before processing the order.
This page calls the CW payment processor include file in order
to pass data to the payment processor.
================================================================
*/
// Initialize transaction variables
$transactionResult = "";
$transactionID = "";
$transactionMessage = "";
if(!isset($_SESSION["order_Comments"])) $_SESSION["order_Comments"] = "";
/* getUniqueOrderId: create a unique order id and check it in the database */
function getUniqueOrderId($size=20, $formatString = '', $prefix="cw") {
// $size defaults to 20 characters, but can be any number
// $formatString is optional, but allows id to be formatted using 'n' to substitute 
	// for numbers
// GUID uses format string nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn 
global $cartweaver;
$orderid = md5(uniqid("CW"));
$orderid = $prefix . $orderid;
$orderid = substr($orderid, 0, $size);
if($formatString != '') {
	while(strlen($orderid) < strlen($formatString)) {
		$orderid .= md5(uniqid("CW"));
	}
	$neworderid = "";
	for($i=0; $i<strlen($formatString); $i++) {
		if(substr($formatString, $i, 1) == "n") {
			$neworderid .= substr($orderid, $i, 1);
		}else{
			$neworderid .= substr($formatString, $i, 1);
		}
	}
	$orderid = $neworderid;
}
$query_rsCWGetId = "SELECT order_ID FROM tbl_orders WHERE order_ID = '$orderid'";
$rsCWGetId = $cartweaver->db->executeQuery($query_rsCWGetId, "rsCWGetId");
$rsCWGetId_recordCount = $cartweaver->db->recordCount;
if($rsCWGetId_recordCount > 0) {
	return getUniqueOrderId($size);
}else{
	return $orderid;
}
}

if(isset($_SESSION["CartId"])){
/* Validate Credit Card Input */
if(strtolower($cartweaver->settings->paymentAuthType) == "gateway") {
	if(isset($_POST)) foreach($_POST as $key=>$value) {
		$_POST[$key] = cleanHtml($value);
	}
	$cwErrorText = "Please correct the following problems:";
	// Check Card holder name
	if($_POST["cstCCardHolderName"] == "") {
		$cartweaver->setCWError("cwErrorCHN", "Card Holder Name cannot be blank.");
	}

	// Check C Card Type
	if ($_POST["cstCCardType"] == "forgot"){ 
		$cartweaver->setCWError("cwErrorCT","Please choose your credit card type.");
	}

	// Check C Card Number by length and ccv length only
	$ccLength = 16;
	$altccLength = 16;
	$ccvLength = 3;

	if($_POST["cstCCardType"] == "amex"){
		$ccLength = 15;
		$altccLength = 15;
		$ccvLength = 4;
	}
	if($_POST["cstCCardType"] == "visa"){
		$altccLength = 13; // visa now accepts 13 and 16 character numbers, so allow both
	}
	if (!is_numeric($_POST["cstCCNumber"]) || 
		(strlen($_POST["cstCCNumber"]) != $ccLength && strlen($_POST["cstCCNumber"]) != $altccLength)){
		$cartweaver->setCWError("cwErrorCN","You did not enter a valid credit card number.");
	}

	if (!is_numeric($_POST["cstCCV"]) || strlen($_POST["cstCCV"]) < $ccvLength){
		$cartweaver->setCWError("cwErrorCCV","You did not enter a CCV code.");
	}

	// Check C Card Expr Month
	if ($_POST["cstExprMonth"] == "forgot"){
		$cartweaver->setCWError("cwErrorCM","Please choose the month your card expires.");
	}

	// Check C Card Expr Year
	if ($_POST["cstExprYr"] == "forgot"){
		$cartweaver->setCWError("cwErrorCY","Please choose the year your card expires.");
	}
}
/* Check to be sure there are no credit card errors */
if(!$cartweaver->getCWError()) {
    /* If a payment processor or no payment verification is being used, 
	      then approve the transactions */
	if(strtolower($cartweaver->settings->paymentAuthType) == "processor" 
		|| strtolower($cartweaver->settings->paymentAuthType) == "none"){
		$orderStatusID = 1;
		$transactionID = $_SESSION["CartId"];
		$_SESSION["transactionMessage"] = "Approved";
		$transactionResult = "Approved";
	}

	/* [sTART Payment Gateway include file Call] */
	if(strtolower($cartweaver->settings->paymentAuthType) == "gateway"){
		/* Set default values for use in the Gateway */
		$ccardHolderName = $_POST["cstCCardHolderName"];
		$ccardType = $_POST["cstCCardType"];
		$ccNumber = $_POST["cstCCNumber"];
		$exprMonth = $_POST["cstExprMonth"];
		$exprYr = $_POST["cstExprYr"];
		$ccV = $_POST["cstCCV"];
		$ccExprDate = $exprMonth . $exprYr;
		/* Get billing information for Credit Card validation */
		$query_rsCWGetCustBilling = "SELECT c.cst_FirstName, 
		c.cst_LastName, 
		s.stprv_Code, 
		s.stprv_Name, 
		co.country_Code, 
		c.cst_Email, 
		c.cst_Phone, 
		c.cst_Address1, 
		c.cst_Address2, 
		c.cst_City, 
		c.cst_Zip
		FROM tbl_customers c
		INNER JOIN tbl_custstate cs 
		ON c.cst_ID = cs.CustSt_Cust_ID
		INNER JOIN tbl_stateprov s 
		ON s.stprv_ID = cs.CustSt_StPrv_ID
		INNER JOIN tbl_list_countries co			
		ON co.country_ID = s.stprv_Country_ID 			
		WHERE c.cst_ID = '" . $_SESSION["customerID"] . "' 
		AND cs.CustSt_Destination = 'BillTo' ";
		$rsCWGetCustBilling = $cartweaver->db->executeQuery($query_rsCWGetCustBilling, "rsCWGetCustBilling");
		$rsCWGetCustBilling_recordCount = $cartweaver->db->recordCount;
		$row_rsCWGetCustBilling = $cartweaver->db->db_fetch_assoc($rsCWGetCustBilling);

		/* Process the payment and return a result */
		require("ProcessPayment/" . $cartweaver->settings->paymentAuthName);
	}/* [END Payment Gateway include file Call] */
} /* End check for valid credit card data */
/* Transaction APPROVED enter data in database. */
if($transactionResult == "Approved") {
	$query_rsCWGetCustShipping = "SELECT cst_ShpName,
	cst_ShpAddress1, 
	cst_ShpAddress2, 
	cst_ShpCity, 
	stprv_Code, 
	cst_ShpZip, 
	country_Code, 
	cst_Email 
	FROM tbl_customers, 
	tbl_custstate, 
	tbl_stateprov, 
	tbl_list_countries 
	WHERE cst_ID ='" . $_SESSION["customerID"] ."'
	AND stprv_ID = CustSt_StPrv_ID 
	AND CustSt_Cust_ID = cst_ID 
	AND CustSt_Destination ='ShipTo'
	AND country_ID = stprv_Country_ID";
	$rsCWGetCustShipping = $cartweaver->db->executeQuery($query_rsCWGetCustShipping, "rsCWGetCustShipping");
	$rsCWGetCustShipping_recordCount = $cartweaver->db->recordCount;
	$row_rsCWGetCustShipping = $cartweaver->db->db_fetch_assoc($rsCWGetCustShipping);

	/* Keep a tally of applied discounts */
	$appliedDiscounts = array();
	/* Create a New Order ID */
	$thisOrderID = getUniqueOrderId(19,'nnnn-nnnn-nnnn-nnnn');
	/* Insert the order into the database */

	$_REQUEST["shippingDiscount"] = intval($_REQUEST["shippingDiscount"]) != 0 ? intval($_REQUEST["shippingDiscount"]) : "NULL"; 	
	$_SESSION["shipPref"] = $_SESSION["shipPref"] != 0 ? $_SESSION["shipPref"] : "NULL";

	$query_rsCWAddOrder = sprintf("INSERT INTO tbl_orders 
	(order_ID, order_CustomerID, 
	order_Tax, order_Shipping, order_ShippingTax,
	order_Total, order_Status,
	order_ShipMeth_ID, order_Address1, 
	order_Address2, order_City,
	order_Zip, order_Country, 
	order_State, order_TransactionID, 
	order_Date, order_ShipName, order_DiscountID, 
	order_DiscountAmount, order_Comments) 
	VALUES ('%s','%s',%s,%s,%s,%s,'%s',%s,'%s','%s','%s','%s','%s','%s','%s',now(),'%s',%d, %s, '%s')",
	$thisOrderID
	, $_SESSION["customerID"]
	, mySQLFloat($cart["CartTotals"]["Tax"] )
	, mySQLFloat($cart["CartTotals"]["Shipping"] )
	, mySQLFloat($cart["CartTotals"]["ShippingTax"] )
	, mySQLFloat($cart["CartTotals"]["Total"] )
	, $orderStatusID
	, $_SESSION["shipPref"]
	, addslashes($row_rsCWGetCustShipping["cst_ShpAddress1"])
	, addslashes($row_rsCWGetCustShipping["cst_ShpAddress2"])
	, addslashes($row_rsCWGetCustShipping["cst_ShpCity"])
	, addslashes($row_rsCWGetCustShipping["cst_ShpZip"])
	, addslashes($row_rsCWGetCustShipping["country_Code"])
	,addslashes($row_rsCWGetCustShipping["stprv_Code"])
	, $transactionID 
	, addslashes($row_rsCWGetCustShipping["cst_ShpName"])
	, intval($_REQUEST["shippingDiscount"])
	, mySQLFloat($cart["CartTotals"]["ShippingDiscounts"])
	, addslashes($_SESSION["order_Comments"]));
	$rsCWAddOrder = $cartweaver->db->executeQuery($query_rsCWAddOrder, "rsCWAddOrder");

	if (intval($_REQUEST["shippingDiscount"]) != 0) {
		array_push($appliedDiscounts, $_REQUEST["shippingDiscount"]);
	}

	/* // === Now Add SKUs ordered to "OrderItems" Table === // */
	/* Loop through the results and record them */
	foreach($cart["Products"] as $product) {
		$skuTotal = $product["Price"] * $product["Quantity"];
		$query_rsCWAddSKUs = sprintf("INSERT INTO tbl_orderskus 
		( orderSKU_OrderID
		, orderSKU_SKU
		, orderSKU_Quantity
		, orderSKU_UnitPrice
		, orderSKU_SKUTotal
		, orderSKU_Picked
		, orderSKU_TaxRate
		, orderSKU_DiscountID
		, orderSKU_DiscountAmount) 
		VALUES 
		('%s',%d,%d,%s,%s,%d,%s,%d,%s)
		", $thisOrderID
		, $product["SKUID"]
		, $product["Quantity"]
		, mySQLFloat($product["Price"])
		, mySQLFloat($product["SubTotal"])
		, mySQLFloat(0)
		, mySQLFloat($product["Tax"])
		, $product["Discount"]["discountID"]
		, mySQLFloat($product["DiscountAmount"] * $product["Quantity"]));			
		$rsCWAddSKUs = $cartweaver->db->executeQuery($query_rsCWAddSKUs, "rsCWAddSKUs");

		/* Debit purchased quantity from stock on hand. */
		$query_rsCWUpdateSKUs = sprintf("UPDATE tbl_skus
		SET SKU_Stock = SKU_Stock - %d
		WHERE SKU_ID = %d",
		$product["Quantity"],
		$product["SKUID"]);
		$rsCWUpdateSKUs = $cartweaver->db->executeQuery($query_rsCWUpdateSKUs, "rsCWUpdateSKUs");
		/* Add discount from product to the appliedDiscounts list */
		if (intval($product["Discount"]["discountID"]) != 0 && !in_array($product["Discount"]["discountID"], $appliedDiscounts)) {
			array_push($appliedDiscounts, $product["Discount"]["discountID"]);
		}
	}  
	if(count($appliedDiscounts) > 0) {
		cwApplyDiscounts($appliedDiscounts, $_SESSION["customerID"]);
	}

	/* Delete All Items From "Cart" table */
	$cartweaver->clearCart();
	$_SESSION["completeOrderID"] = $thisOrderID;
	/* Redirect to Confirmation page */
	header("Location: " . $cartweaver->settings->targetConfirmOrder); 
	exit();
}else{
	$cartweaver->setCWError("TransactionError",$transactionMessage);
} /* END if($transactionResult == "Approved") */
}else{
  /* no valid cart, redirect the user to the cart page */
header("Location: " . $cartweaver->settings->targetGoToCart);
exit();
}
?>

Link to comment
Share on other sites

Name: CWIncProcessOrder.php

Description:

  The Process Order include file

That file is being included more than once. Either the include statement for it is inside of a loop or you have an include statement more than one time.

 

Could you elaborate any?  Or is it that simple.  I have not altered the php code or structure of the application in any way, and the fact that the application successfully connects to the payment gateway in test mode, but fails to execute the CWIncProcess Order.php file and subsequent confirmation page with either an "approved" or "denied" message to the user is puzzling to my ignorant mind.   

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.