function get_product_name($pid){
global $d, $row,$lang;
$sql = "select ten_$lang from #_product where id='".$pid."'";
$d->query($sql);
$row = $d->fetch_array();
return $row['ten_'.$lang];
}
function get_linkprd($pid){
global $d, $row,$lang;
$sql = "select ten_$lang,tenkhongdau,id from #_product where id='".$pid."'";
$d->query($sql);
$row = $d->fetch_array();
return $row['tenkhongdau'];
}
function get_price($pid){
global $d, $row;
$sql = "select giaban from table_product where id='".$pid."'";
$d->query($sql);
$row = $d->fetch_array();
return $row['giaban'];
}function get_tonggiatracuu(){
global $d, $result,$tonggia;
$tonggia="";
$sql = "select tonggia from table_order where email='".$_SESSION['login']['email']."'";
$d->query($sql);
$result = $d->result_array();
foreach((array)$result as $item){
$tonggia+=$item['tonggia'];
}
return $tonggia;
}
function get_giatracuu($pid){
global $d, $result;
$sql = "select tonggia from table_order where id='".$pid."'";
$d->query($sql);
$result = $d->fetch_array();
return $result['tonggia'];
}
function get_thumb($pid){
global $d, $row;
$sql = "select thumb from table_product where id='".$pid."' ";
$d->query($sql);
$row = $d->fetch_array();
return $row['thumb'];
}
function get_size($id_size){
global $d, $row;
$sql = "select size from table_size where id_size='".$id_size."' ";
$d->query($sql);
$row = $d->fetch_array();
return $row['size'];
}
function get_size1($id_size){
global $d, $row,$lang;
$sql = "select id,ten_".$lang." as ten from table_baiviet where hienthi=1 and type='size' and id='".$id_size."' ";
$d->query($sql);
$row = $d->fetch_array();
return $row['ten'];
}
function get_cotbanh($id_cotbanh){
global $d, $row,$lang;
$sql = "select id,ten_".$lang." as ten from table_baiviet where hienthi=1 and type='cotbanh' and id='".$id_cotbanh."' ";
$d->query($sql);
$row = $d->fetch_array();
return $row['ten'];
}
function get_nhanbanh($id_nhanbanh){
global $d, $row,$lang;
$sql = "select id,ten_".$lang." as ten from table_baiviet where hienthi=1 and type='nhanbanh' and id='".$id_nhanbanh."' ";
$d->query($sql);
$row = $d->fetch_array();
return $row['ten'];
}
function get_loaixot($id_loaixot){
global $d, $row,$lang;
$sql = "select id,ten_".$lang." as ten from table_baiviet where hienthi=1 and type='loaixot' and id='".$id_loaixot."' ";
$d->query($sql);
$row = $d->fetch_array();
return $row['ten'];
}
function get_mau($id_mau){
global $d, $row;
$sql = "select hinh from table_mau where id_mau='".$id_mau."' ";
$d->query($sql);
$row = $d->fetch_array();
return $row['hinh'];
}
function get_giatour($id_tour){
global $d, $ds_giasaigon;
$sql = "select * from #_giasaigon where id_saigon='".$id_tour."'";
$d->query($sql);
$ds_giasaigon = $d->fetch_array();
return $ds_giasaigon;
}
function remove_product($pid/*,$thongtin*/){
$pid=intval($pid);
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid'] /* && $thongtin==$_SESSION['cart'][$i]['thongtin']*/){
unset($_SESSION['cart'][$i]);
break;
}
}
$_SESSION['cart']=array_values($_SESSION['cart']);
}
function remove_pro_thanh($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
unset($_SESSION['cart'][$i]);
break;
}
}
$_SESSION['cart']=array_values($_SESSION['cart']);
redirect('thanh-toan.html');
}
function get_order_total(){
$max=count($_SESSION['cart']);
$sum=0;
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
$sum+=$price*$q;
}
return $sum;
}
function addtocart($pid,$q){
if($pid<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($pid,$q)) return 0;
// thêm cái khác vào ko có trong dieu kien se tien hành add vao vi tri max
// $_SESSION['cart'][$max]['productid']=$pid; nghia la $a[$key]
// có 2->count=2
// mảng $_SESSION[cart] chay tu 0 ->tuc tự động them vao vi trí 3
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
// $_SESSION['cart'][$max]['id_mau']=$id_mau;
$_SESSION['cart'][$max]['qty']=$q;
// $_SESSION['cart'][$max]['songay']=$songay;
return count($_SESSION['cart']);
}
else{
$_SESSION['cart'][0]['productid']=$pid;
// $_SESSION['cart'][0]['id_mau']=$id_mau;
$_SESSION['cart'][0]['qty']=$q;
// $_SESSION['cart'][0]['songay']=$songay;
return count($_SESSION['cart']);
}
// nguoc lai nghia la gio hang chua ton tai
// tien hanh tao mang va them gia tri vi tri thu 0
}
function product_exists($pid,$q){
$pid=intval($pid);
$max=count($_SESSION['cart']);
$flag=0;
for($i=0;$i<$max;$i++){
// neu id = id trong gio hang
if($pid==$_SESSION['cart'][$i]['productid']){
// tien hanh cong cai so luong hien tai voi so luong vua them
//nguoc lai flag = 0 tuc la ko co gia tri cong them cho ham
$_SESSION['cart'][$i]['qty'] = $_SESSION['cart'][$i]['qty'] + $q;
$flag=1;
break;
}
}
return $flag;
}
?>