-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage_cart.php
More file actions
49 lines (46 loc) · 2.17 KB
/
manage_cart.php
File metadata and controls
49 lines (46 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
include "functions/function.php";
if($_POST['type']=="addToCart"){
$size=$_POST['size'];
$color=$_POST['color'];
$qty=$_POST['qty'];
$pro_id=$_POST['pid'];
$ip_add=getUserIP();
$prodpre="select * from addcart where product_id='$pro_id' and ip_address='$ip_add'";
$res=mysqli_query($conn,$prodpre);
if(mysqli_num_rows($res)>0){
$arr=array("error"=>"itemAlreadyPresent");
echo json_encode($arr);
}else{
if(isset($_SESSION['size']) && isset($_SESSION['color'])){
$color=$_SESSION['color'];
$size=$_SESSION['size'];
unset($_SESSION['size']);
unset($_SESSION['color']);
}
$totalprice=0;
$resattr=mysqli_query($conn,"select attribute_id from product_attribute where product_id='$pro_id' and product_color='$color' and product_size='$size'");
$rowattr=mysqli_fetch_assoc($resattr);
$attr_id=$rowattr['attribute_id'];
$getprodcart="insert into addcart (product_id,ip_address,qty,attribute_id) values('$pro_id','$ip_add','$qty','$attr_id')";
$res=mysqli_query($conn,$getprodcart);
$prodpre="select * from addcart where ip_address='$ip_add' order by 1 desc";
$res1=mysqli_query($conn,$prodpre);
$count=mysqli_num_rows($res1);
$rowcart=mysqli_fetch_assoc($res1);
$pro_id=$rowcart['product_id'];
$attr_id=$rowcart['attribute_id'];
$qty=$rowcart['qty'];
$getpro=mysqli_query($conn,"select * from products where product_id='$pro_id'");
$rowpro=mysqli_fetch_assoc($getpro);
$img1=$rowpro['product_img1'];
$pname=$rowpro['product_name'];
$getattr=mysqli_query($conn,"select * from product_attribute where attribute_id='$attr_id'");
$rowattr=mysqli_fetch_assoc($getattr);
$pprice=$rowattr['product_price'];
$getCartTotalPrice=getCartTotalPrice();
$arr=array("totalitem"=>$count, "totalprice"=>$getCartTotalPrice,"success"=>"itemadded","product_img"=>$img1,"product_name"=>$pname,"product_qty"=>$qty,"product_price"=>$pprice);
echo json_encode($arr);
}
}
?>