⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fun.cart.php

📁 很好的电子商务程序,品品哈哈哈好的很好的很
💻 PHP
字号:
<?php

/*----------------------------------------------------
	[ShoopD] includes/cart.php 

	Version: 1.5
	Author: soolan (soolan@qq.com)
	Copyright: soolan (www.shoopd.com)
	Last Modified: 2006/2/1 10:00

----------------------------------------------------*/
    
    
function cart_add_product($products_id){
	global $db, $table_products;
	if(cart_exists($products_id)){
		$_SESSION['cart'][$products_id]["quantity"]   = intval($_SESSION['cart'][$products_id]["quantity"])+1;
	}else{
		$products_data = $db->get_one("SELECT COUNT(*) AS count from $table_products where products_id = '" . (int)$products_id . "'");
		if($products_data['count'] > 0){
			$_SESSION['cart'][$products_id]["quantity"] = 1;
		}
	}
}

function cart_exists($id){
	if(!function_exists('array_key_exists')) {
		function array_key_exists($id,$soobic) {
			return key_exists($id,$soobic);
		}
	}
	if($_SESSION['cart'][$id] && @array_key_exists($id,$_SESSION['cart'])){
		return true;
	}else{
		return false;
	}
}

function cart_mod_product($id,$quantity){
	$arr = cart_get_product($id);
	if(cart_exists($id)){
		if($quantity < 1){
			cart_empty_cart($id);
		}else{
			$_SESSION['cart'][$id]['quantity']   = intval($quantity);
		}
	}
}

function cart_get_product($id = null){
	if(isset($_SESSION['cart'])){
		if($id == null){
			return $_SESSION['cart'];
		}else{
			return $_SESSION['cart'][$id];
		}	
	}
}

function cart_empty_cart($id = null){
	if($id == null){
		unset($_SESSION['cart']);
	}else{
		unset($_SESSION['cart'][$id]);
	}
}
    
function cart_get_weight(){   
	global $db, $table_products;
	$total = 0;
	if(is_array($_SESSION['cart']) && $_SESSION['cart']['0']) {
		foreach($_SESSION['cart'] as $key=>$val){
			$products_data = $db->get_one("select weight from $table_products where products_id = '" . (int)$key . "'");
			$total += (floatval($products_data['weight'])*intval($val['quantity']));
		}
	}
	return $total;
}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -