Location: PHPKode > projects > Simple PHP Shopping cart - asaancart > asaancart v-0.9/shop/receipt.php
<?php
session_start();
/*
asaancart - easy shopping cart solution
---------------------------------------

Copyright 2009 Nasir Ahmad Khan
Email: hide@address.com

This file is part of asaancart - open source easy shopping cart solution.

asaancart is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

asaancart is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with asaancart.  If not, see <http://www.gnu.org/licenses/>.

*/

include("../config/config.php");
include("classes/functions.php");
if (session_id() == "") session_start();
$session_id = session_id();

include("includes/global_settings.php");

$smarty->assign('shippingTotal',shippingRate(getCartTotalAmount($session_id)));
$cartTotal  = getCartTotalAmount($session_id)+ shippingRate(getCartTotalAmount($session_id));
//end shipping cost

$smarty->assign('cartTotal',$cartTotal);

$smarty->assign('cartItems',getCartItems($session_id));
$smarty->assign('cartSubTotal', getCartTotalAmount($session_id));

$shippingTotal = shippingRate(getCartTotalAmount($session_id));
$cartSubTotal = getCartTotalAmount($session_id);
$customer_name = $_POST['customer_name'];
$_SESSION['customer_name'] = $customer_name;

$business_name = $_POST['business_name'];
$_SESSION['business_name'] = $business_name;
if($business_name==""){$business_name = " ";}
$email_address = $_POST['email_address'];
$_SESSION['email_address'] = $email_address;

$customer_mobile = $_POST['customer_mobile'];
$_SESSION['mobile'] = $customer_mobile;

$customer_phone = $_POST['customer_phone'];
$_SESSION['phone'] = $customer_phone;

$customer_state = $_POST['customer_state'];
$_SESSION['state'] = $customer_state;

$customer_city = $_POST['customer_city'];
$_SESSION['city'] = $customer_city;

$customer_suburb = $_POST['customer_suburb'];
$_SESSION['suburb'] = $customer_suburb;

$customer_postcode = $_POST['customer_postcode'];
$_SESSION['postcode'] = $customer_postcode;

$customer_address = $_POST['customer_address'];
$_SESSION['address'] = $customer_address;

$s_customer_country = $_POST['s_customer_country'];
$_SESSION['shipping_country'] = $s_customer_country;

$s_customer_state = $_POST['s_customer_state'];
$_SESSION['shipping_state'] = $s_customer_state;

$s_customer_city = $_POST['s_customer_city'];
$_SESSION['shipping_city'] = $s_customer_city;

$s_customer_postcode = $_POST['s_customer_postcode'];
$_SESSION['shipping_postcode'] = $s_customer_postcode;

$s_customer_suburb = $_POST['s_customer_suburb'];
$_SESSION['shipping_suburb'] = $s_customer_suburb;

$s_customer_address = $_POST['s_customer_address'];
$_SESSION['shipping_address'] = $s_customer_address;

$shipping_instructions = $_POST['shipping_instructions'];
$_SESSION['shipping_instructions'] = $shipping_instructions;

$mailing_list = $_POST['mailing_list'];
if($mailing_list!="yes"){$mailing_list = "no";}

$payment_option = $_POST['payment_option'];

if($payment_option=="bank_deposit"){
	$payment_instructions = getPaymentInstructionsBD();
}elseif($payment_option=="bank_check"){
	$payment_instructions = getPaymentInstructionsBC();
}elseif($payment_option=="money_order"){
	$payment_instructions = getPaymentInstructionsMO();
}

$smarty->assign('payment_instructions',$payment_instructions);

$error_msg = "";
if($customer_name==""){
$error_msg .= "Customer Name <br />";
}
if($email_address==""){
$error_msg .= "Email Address <br />";
}
if($customer_phone==""){
$error_msg .= "Phone <br />";
}
if($customer_state==""){
$error_msg .= "State <br />";
}
if($customer_city==""){
$error_msg .= "City <br />";
}
if($customer_postcode==""){
$error_msg .= "Postcode <br />";
}
if($customer_address==""){
$error_msg .= "Address <br />";
}
if($s_customer_country==""){
$error_msg .= "Shipping Country <br />";
}
if($s_customer_state==""){
$error_msg .= "Shipping State <br />";
}
if($s_customer_city==""){
$error_msg .= "Shipping City <br />";
}
if($s_customer_postcode==""){
$error_msg .= "Shipping Postcode <br />";
}
if($s_customer_address==""){
$error_msg .= "Shipping Address <br />";
}


if($error_msg!=""){
	header("location: checkout.php?error_msg=".$error_msg);
}else{

if(getCartTotalQty($session_id)>0){
	$max_order_id = getMaxOrderId();
	$new_order_id = $max_order_id + 1;
	$order_number = $order_prefix.$new_order_id;
	
	$smarty->assign('order_number', $order_number);
	$smarty->assign('customer_name', $customer_name);
	$smarty->assign('bunisess_name', $business_name);
	$smarty->assign('email_address', $email_address);
	$smarty->assign('address', $s_customer_address);
	$smarty->assign('city', $s_customer_city);
	$smarty->assign('state', $s_customer_state);
	$smarty->assign('post_code', $s_customer_postcode);
	$smarty->assign('country', $s_customer_country);
	$smarty->assign('payment_method', $payment_option);
	$smarty->assign('phone_number', $customer_phone);
	$smarty->assign('order_date', date("d-m-Y"));
	$smarty->assign('order_instructions', $shipping_instructions);
	
	$smarty->assign('payment_options_available', getDefaultPaymentOptions());
	
	
	
	
	//add user
	$sql = "INSERT INTO customers (customer_name, business_name, customer_country, customer_state, customer_city, customer_suburb, customer_postcode, customer_mobile, customer_phone, email_address, customer_address, s_customer_country, s_customer_state, s_customer_city, s_customer_suburb, s_customer_postcode, s_customer_address, mailing_list) VALUES ('$customer_name', '$business_name', '$customer_country', '$customer_state', '$customer_city', '$customer_suburb', '$customer_postcode', '$customer_mobile', '$customer_phone', '$email_address', '$customer_address', '$s_customer_country', '$s_customer_state', '$s_customer_city', '$s_customer_suburb', '$s_customer_postcode', '$s_customer_address', '$mailing_list')";
	$results = mysql_query($sql);
	//end add user
	
	//add order
	$sql = "INSERT INTO orders (order_number, customer_name, customer_email, state, city, shipping_address, postcode, country, payment_method, order_comments, order_date, order_status, order_shipping, order_subtotal) VALUES ('$order_number', '$customer_name', '$email_address', '$s_customer_state', '$s_customer_city', '$s_customer_address', '$s_customer_postcode', '$s_customer_country', '$payment_option', '$shipping_instructions', '".date("d-m-Y")."', 'pending', $shippingTotal, $cartSubTotal)";
	$results = mysql_query($sql);
	
	
	//end add order
	
	//add order items
	$sqlCart = "SELECT * FROM my_cart WHERE session_id = '$session_id' ORDER BY product_name";
		$resultsCart = mysql_query($sqlCart);
		while($rowCart = mysql_fetch_array($resultsCart) )
		{
			$product_code = $rowCart['product_code'];
			$product_id = $rowCart['product_id'];
			$product_name = $rowCart['product_name'];
			$product_name = $product_name;//."<br />".$rowCart['product_description'];
			$product_name = str_replace("'","\'",$product_name);
			$product_quantity = $rowCart['product_qty'];
			$product_price = $rowCart['product_price'];
			$sub_total = $rowCart['total'];
			$stock_ref = $rowCart['stock_ref'];
			
			$sql = "INSERT INTO order_item (order_number, product_code, product_name, product_quantity, product_price, sub_total, stock_ref, product_id) VALUES ('$order_number', '$product_code', '$product_name', $product_quantity, $product_price, $sub_total, '$stock_ref', '$product_id')";
	$results = mysql_query($sql);
	
	
		}
		
		
	
	//end add items

}

$smarty->assign('site_url', SITE_URL);


$results = mysql_query("DELETE FROM my_cart WHERE session_id = '$session_id'");

session_unset();
session_destroy();
$_SESSION = array();





$smarty->assign('payment_options_available', getDefaultPaymentOptions());
$smarty->assign('template','receipt');

$smarty->display('shop/site_index.tpl');

}//end err if
?>
Return current item: Simple PHP Shopping cart - asaancart