ok
Direktori : /home2/selectio/public_html/thecomponents.in/api/ |
Current File : /home2/selectio/public_html/thecomponents.in/api/cart.php |
<?php session_start(); include"../config/config.php"; error_log("page is wworkinf"); if(isset($_POST['type']) && $_POST['type']=='add_to_cart') { try { if(isset($_SESSION['caliber'])){ $user_id=$_SESSION['caliber']['id']; $statementp=$pdo->prepare("SELECT * FROM `cart` where product_id=? AND user_id=?"); $statementp->execute(array($_POST['product_id'],$user_id)); $totalp=$statementp->rowCount(); $resultp=$statementp->fetchAll(PDO::FETCH_ASSOC); if($totalp==0) { $qty = $_POST['quantiy']; error_log($qty); $statement=$pdo->prepare("INSERT INTO `cart`(`user_id`,`product_id`,`qty`) VALUES (?,?,?)"); $result=$statement->execute(array($user_id,$_POST['product_id'],$qty)); if($result) { $statementp=$pdo->prepare("SELECT * FROM `cart` where user_id=? AND product_id=? group by product_variant_id"); $statementp->execute(array($user_id,$_POST['product_id'])); $cart_count=$statementp->rowCount(); $return_arr['cart_count']="$cart_count"; $return_arr['message'] = "Addtocard successfully Added!"; $return_arr['status']=200; } else { $return_arr['message']="Please add product details!"; $return_arr['status']=400; } }else{ $return_arr['message']="product already in Addtocart!"; $return_arr['status']=400; } }else{ //session not value else part $return_arr['message']="Please login!"; $return_arr['status']=500; } echo json_encode($return_arr); } catch(Exception $e){ $return_arr['message']='0987'.$e; $return_arr['status']=500; echo json_encode($return_arr); } } ?>