Location: PHPKode > projects > Simple PHP Shopping cart - asaancart > asaancart v-0.9/shop/cart.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");

$product_name = $_GET['product_name'];
$product_id = $_GET['product_id'];
$mode = $_GET['mode'];
$id = $_GET['id'];

/*
*/
$selected_product_variant = $_GET['selected_product_variant'];
$selected_variant_id = $_GET['selected_variant_id'];



$smarty->assign('productData',getProductById($product_id));
$smarty->assign('productDataImages',getImagesByProductId($product_id));
 


$smarty->assign('relatedProducts',getRelatedProducts($product_id));
$smarty->assign('crossSellingProducts',getCrossSellingProducts($product_id));
$smarty->assign('totalRelatedProducts',getTotalRelatedProducts($product_id));
$smarty->assign('totalCrossSellingProducts',getTotalCrossSellingProducts($product_id));

$smarty->assign('productTag','');
$smarty->assign('imgCnt',0);

$smarty->assign('title',getProductColumnById('product_name',$product_id));

$smarty->assign('product_price',getProductColumnById('product_price',$product_id));
$product_price = getProductColumnById('product_price',$product_id);

$smarty->assign('product_deal_price',getProductColumnById('product_deal_price',$product_id));
$product_deal_price = getProductColumnById('product_deal_price',$product_id);

if($product_deal_price > 0){
$product_price_for_cart = $product_deal_price;
}else{
$product_price_for_cart = $product_price;
}

$smarty->assign('product_qty',getProductColumnById('product_qty',$product_id));
$smarty->assign('product_code',getProductColumnById('product_code',$product_id));
$smarty->assign('variant_level_stock',getProductColumnById('variant_level_stock',$product_id));

//get product variants
$smarty->assign('productVariants',getProductVariants($product_id));
$smarty->assign('variantGroups',getVariantGroups());
$smarty->assign('productVariantGroups',getProductVariantGroups($product_id));


$productSelectedVariantSurchargeTotal = 0;

//get Total Qty
if(getProductColumnById('variant_level_stock',$product_id)=="no"){
	$smarty->assign('totalProductQty',getProductColumnById('product_qty',$product_id));
	$totalProductQty = getProductColumnById('product_qty',$product_id);
	$totalSelectedProductInStock = getProductColumnById('product_qty',$product_id);
	$stockRef = "product_based_stock_level";
	
	$productSelectedVariantName = "";
	$pcnt = 0;
	$tempProductVariantGroupArray = getProductVariantGroups($product_id);
	
	if($tempProductVariantGroupArray[0]!=""){
	
		foreach($tempProductVariantGroupArray as $tempProductVariantGroup){
		
			if($pcnt==0){
				$productSelectedVariantName = " | ".getProductVariantNameById($_GET['selected_product_variant_'.$tempProductVariantGroup['variant_group_id']]);
				$pcnt=1;
			}else{
			$productSelectedVariantName = $productSelectedVariantName." | ".getProductVariantNameById($_GET['selected_product_variant_'.$tempProductVariantGroup['variant_group_id']]);
			}
			
		//get surcharge
		$productSelectedVariantSurchargeTotal = $productSelectedVariantSurchargeTotal + getProductVariantSurchargeById($_GET['selected_product_variant_'.$tempProductVariantGroup['variant_group_id']]);
		//end get surcharge
			
		}
	}
	$product_name = $product_name. "  ". $productSelectedVariantName;
	
	///end create product name
	
	
}elseif(getProductColumnById('variant_level_stock',$product_id)=="yes"){
	$smarty->assign('totalProductQty',getProductTotalQtyByVariants($product_id));
	$totalProductQty = getProductTotalQtyByVariants($product_id);
	


	$productSelectedVariantName = "";
	$pcnt = 0;
	$tempProductVariantGroupArray = getProductVariantGroups($product_id);
	foreach($tempProductVariantGroupArray as $tempProductVariantGroup){
	
	if(getProductColumnById('stock_variant_group_id',$product_id)==$tempProductVariantGroup['variant_group_id']){
	$totalSelectedProductInStock = getProductTotalQtyOfVariant($_GET['selected_product_variant_'.$tempProductVariantGroup['variant_group_id']]);
	$stockRef = $_GET['selected_product_variant_'.$tempProductVariantGroup['variant_group_id']]; //variant id
	
	
	}
		if($pcnt==0){
			$productSelectedVariantName = " | ".getProductVariantNameById($_GET['selected_product_variant_'.$tempProductVariantGroup['variant_group_id']]);
			$pcnt=1;
		}else{
		$productSelectedVariantName = $productSelectedVariantName." | ".getProductVariantNameById($_GET['selected_product_variant_'.$tempProductVariantGroup['variant_group_id']]);
		}
		
	
	//get surcharge
	$productSelectedVariantSurchargeTotal = $productSelectedVariantSurchargeTotal + getProductVariantSurchargeById($_GET['selected_product_variant_'.$tempProductVariantGroup['variant_group_id']]);
	//end get surcharge
		
	}
	
	$product_name = $product_name. "  ". $productSelectedVariantName;
	
	/*
	if($_GET['selected_product_variant']!=""){
		$totalSelectedProductInStock = getProductTotalQtyOfVariant($_GET['selected_product_variant']);
		$productSelectedVariantName = getProductVariantNameById($_GET['selected_product_variant']);
		$product_name = $product_name." - ".$productSelectedVariantName;
		$stockRef = $_GET['selected_product_variant'];
	}
	*/
	
}

$smarty->assign('variant_level_stock',getProductColumnById('variant_level_stock',$product_id));

$smarty->assign('stock_variant_group_id',getProductColumnById('stock_variant_group_id',$product_id));

//add to cart
//add to cart
if($mode == "add"){
$selected_product_description = substr(getProductColumnById('product_description',$product_id), 0, 125)."...";
$temp_additional_description = "";
$temp_surcharge_total = $productSelectedVariantSurchargeTotal;
$extras = 0.00;

$qty_entered = $_GET['qty_entered'];

//if($qty_entered > $totalSelectedProductInStock){$qty_entered = $totalSelectedProductInStock;}

if($temp_surcharge_total>0){
	$total = ($temp_surcharge_total+$product_price_for_cart)*$qty_entered;
	$product_price = $temp_surcharge_total+$product_price_for_cart;
	$extras = $temp_surcharge_total;
}else{
	$total = $product_price_for_cart*$qty_entered;
	$product_price = $product_price_for_cart;
}

		$sql = "SELECT * FROM my_cart WHERE product_id='$product_id' AND session_id='$session_id' AND product_name='$product_name'";
		$results = mysql_query($sql);
		
		$is_found = mysql_num_rows($results);
	
	if ($is_found>0){
	$smarty->assign('msg',"<div style='color:red; font-weight:bold;'>Sorry, <strong>$product_name</strong> already in your cart. Please update quantity if you want to add more.</div>");
	}else{
	$sql = "INSERT INTO my_cart (product_code, session_id, product_id, product_name, product_price, product_image, product_qty, total, extras, stock_ref, qty_limit) VALUES ('".getProductColumnById('product_code',$product_id)."', '$session_id', '$product_id', '$product_name', ".$product_price.", '".getProductMainImageById($product_id)."', $qty_entered, $total, $extras, '$stockRef', $totalSelectedProductInStock)";
		$results = mysql_query($sql);
		
		$smarty->assign('msg',"<div style='color:black; font-weight:normal;'>Done, <strong>$product_name</strong> added successfully into your cart</div>");
		
	}// found chk
	
	
		
		
		
		//}// found chk
}


//end add to cart
//shipping cost
//$activeShippingClass = getAvtiveShippingClass();
//$smarty->assign('totalShippingCost',getTotalShipping($activeShippingClass, getCartTotalAmount($session_id) ));

$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));
$smarty->assign('product_id',$product_id);
$smarty->assign('product_name',$product_name);
$smarty->assign('total_cart_items', getCartTotalItems($session_id));
$smarty->assign('totalSelectedProductInStock', $totalSelectedProductInStock);
//express checkout
$smarty->assign('paymentType','sale');
$smarty->assign('currencyCodeType',getStoreBasicInfoByOneParam('currency'));
//echo getStoreBasicInfoByOneParam('currency');
$smarty->assign('template','cart');

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


?>
Return current item: Simple PHP Shopping cart - asaancart