query($sql); $row = $d->fetch_array(); return $row['ten_'.$lang]; } function get_product($pid,$loai,$loaigia){ global $d, $row,$lang; $sql = "select ten_$lang as ten,id_cat,giaban from table_product where id='".$pid."'"; $d->query($sql); $row = $d->fetch_array(); if($loai==0) { $sql = "select $loaigia as giaban from table_product_cat where id='".$row['id_cat']."'"; $d->query($sql); $tmp = $d->fetch_array(); $row['giaban']=$tmp['giaban']; } return $row; } 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_color($color_id){ global $d, $row; $sql = "select ten_$lang as ten from table_baiviet where id='".$color_id."'"; $d->query($sql); $row = $d->fetch_array(); return $row['ten']; // dump($row['thumb']); } 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_thumb_color($pid){ global $d, $row; $sql = "select thumb from table_product_photo where id='".$pid."' "; $d->query($sql); $row = $d->fetch_array(); return $row['thumb']; } 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,$color_id){ if($pid<1 or $q<1) return; if(is_array($_SESSION['cart'])){ if(product_exists($pid,$q,$color_id)) return 0; $max=count($_SESSION['cart']); $_SESSION['cart'][$max]['productid']=$pid; $_SESSION['cart'][$max]['qty']=$q; $_SESSION['cart'][$max]['mausp']=$color_id; return count($_SESSION['cart']); } else{ $_SESSION['cart']=array(); $_SESSION['cart'][0]['productid']=$pid; $_SESSION['cart'][0]['qty']=$q; $_SESSION['cart'][0]['mausp']=$color_id; return count($_SESSION['cart']); } } function product_exists($pid,$q,$color_id){ $pid=intval($pid); $max=count($_SESSION['cart']); $flag=0; for($i=0;$i<$max;$i++){ if($pid==$_SESSION['cart'][$i]['productid'] && $color_id==$_SESSION['cart'][$i]['mausp']){ $_SESSION['cart'][$i]['qty'] = $_SESSION['cart'][$i]['qty'] + $q; $flag=1; break; } } return $flag; } ?>