Location: PHPKode > projects > Simple PHP Shopping cart - asaancart > asaancart v-0.9/shop/update_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'];


$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));
$smarty->assign('product_deal_price',getProductColumnById('product_deal_price',$product_id));
$smarty->assign('product_qty',getProductColumnById('product_qty',$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));


//get Total Qty for variant and product based stock
if(getProductColumnById('variant_level_stock',$product_id)=="no"){ //could also be no_stock_level
	$smarty->assign('totalProductQty',getProductColumnById('product_qty',$product_id));
	$totalProductQty = getProductColumnById('product_qty',$product_id);
	$totalSelectedProductInStock = getProductColumnById('product_qty',$product_id);
}elseif(getProductColumnById('variant_level_stock',$product_id)=="yes"){
	$smarty->assign('totalProductQty',getProductTotalQtyByVariants($product_id));
	$totalProductQty = getProductTotalQtyByVariants($product_id);
	$totalSelectedProductInStock = $_GET['max_qty'];
	
}
//if no stock is maintained then use the qty entered by the user in the shopping cart
if(getProductColumnById('stock_options',$product_id)=="no_stock_level"){ 
	$totalSelectedProductInStock = $_GET['product_qty'];
}


if ($mode=="update_qty"){
$product_qty2 = $_GET['product_qty'];

if($product_qty2 > $totalSelectedProductInStock){$product_qty2 = $totalSelectedProductInStock;}


$extras = getCartProductColumnById('extras',$id);
$cart_price = $extras+getProductColumnById('product_price',$product_id);
$total2 = $cart_price*$product_qty2;

//$total2 = $total2 + $extras;
//echo $total2."  ".getProductColumnById('product_price',$product_id)."  ".$extras;
//echo $product_qty2;	
	$sql_img = "UPDATE my_cart SET product_qty=$product_qty2, total=$total2 WHERE id=$id";
	$results_img = mysql_query($sql_img);
	$smarty->assign('msg', "<div style='color:black; font-weight:normal;'>Done, Cart Updated</div>");
		//}// found chk
////

}

if ($mode=="delete"){
	$sql_img = "DELETE FROM my_cart WHERE id=$id";
	$results_img = mysql_query($sql_img);
	$smarty->assign('msg', "Cart updated");

}

$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));
$smarty->assign('product_deal_price',getProductColumnById('product_deal_price',$product_id));
$smarty->assign('product_qty',getProductColumnById('product_qty',$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));


/*
//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);
}elseif(getProductColumnById('variant_level_stock',$product_id)=="yes"){
	$smarty->assign('totalProductQty',getProductTotalQtyByVariants($product_id));
	$totalProductQty = getProductTotalQtyByVariants($product_id);
	if($_GET['selected_product_variant']!=""){
		$totalSelectedProductInStock = getProductTotalQtyOfVariant($_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
//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', $max_qty);

//$smarty->assign('template','cart');

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


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