Commit 3643f98a by Jansa Jose

webservices for web and app

parent 59ba94a6
...@@ -57,7 +57,7 @@ class Product extends CI_Controller { ...@@ -57,7 +57,7 @@ class Product extends CI_Controller {
$flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error'); $flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error');
if(!isset($_POST) || empty($_POST)){ if(!isset($_POST) || empty($_POST)){
$this->session->set_flashdata('message',$flashMsg); $this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Product/addProduct')); redirect(base_url('Product/addproduct'));
} }
if($err == 0 && (!isset($_POST['brand_id']) || empty($_POST['brand_id']))){ if($err == 0 && (!isset($_POST['brand_id']) || empty($_POST['brand_id']))){
$err = 1; $err = 1;
...@@ -91,7 +91,7 @@ class Product extends CI_Controller { ...@@ -91,7 +91,7 @@ class Product extends CI_Controller {
if($err == 1){ if($err == 1){
$flashMsg['message'] = $errMsg; $flashMsg['message'] = $errMsg;
$this->session->set_flashdata('message',$flashMsg); $this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Product/addProduct')); redirect(base_url('Product/addproduct'));
} }
$product_id = $this->Product_model->addProduct($_POST); $product_id = $this->Product_model->addProduct($_POST);
...@@ -125,7 +125,7 @@ class Product extends CI_Controller { ...@@ -125,7 +125,7 @@ class Product extends CI_Controller {
redirect(base_url('Product/viewProducts')); redirect(base_url('Product/viewProducts'));
}else { }else {
$this->session->set_flashdata('message', $flashMsg); $this->session->set_flashdata('message', $flashMsg);
redirect(base_url('Product/addProduct')); redirect(base_url('Product/addproduct'));
} }
} }
} }
...@@ -137,7 +137,7 @@ class Product extends CI_Controller { ...@@ -137,7 +137,7 @@ class Product extends CI_Controller {
redirect(base_url('Product/viewProducts')); redirect(base_url('Product/viewProducts'));
} }
$template['page'] = 'Product/addProduct'; $template['page'] = 'Product/addproduct';
$template['menu'] = 'Brand Management'; $template['menu'] = 'Brand Management';
$template['smenu'] = 'Edit brand'; $template['smenu'] = 'Edit brand';
$template['pTitle'] = "Edit brand"; $template['pTitle'] = "Edit brand";
...@@ -162,7 +162,7 @@ class Product extends CI_Controller { ...@@ -162,7 +162,7 @@ class Product extends CI_Controller {
} }
if(!isset($_POST) || empty($_POST)){ if(!isset($_POST) || empty($_POST)){
$this->session->set_flashdata('message',$flashMsg); $this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Product/addProduct')); redirect(base_url('Product/addproduct'));
} }
if($err == 0 && (!isset($_POST['brand_id']) || empty($_POST['brand_id']))){ if($err == 0 && (!isset($_POST['brand_id']) || empty($_POST['brand_id']))){
$err = 1; $err = 1;
...@@ -196,7 +196,7 @@ class Product extends CI_Controller { ...@@ -196,7 +196,7 @@ class Product extends CI_Controller {
if($err == 1){ if($err == 1){
$flashMsg['message'] = $errMsg; $flashMsg['message'] = $errMsg;
$this->session->set_flashdata('message',$flashMsg); $this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Product/addProduct')); redirect(base_url('Product/addproduct'));
} }
$existingImages = (isset($_POST['existingImages']) && !empty($_POST['existingImages']))? $existingImages = (isset($_POST['existingImages']) && !empty($_POST['existingImages']))?
$_POST['existingImages']:''; $_POST['existingImages']:'';
......
...@@ -2061,6 +2061,140 @@ ...@@ -2061,6 +2061,140 @@
$result = $this->Webservice_model->cancelOrder($postData); $result = $this->Webservice_model->cancelOrder($postData);
echo json_encode($result);exit; echo json_encode($result);exit;
} }
public function getCartData(){
header('Content-type:application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$total = 0;
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] != 1) ?$postData['page'] :'1';
$page_limit = ($page - 1) * $per_page;
$result = $this->Webservice_model->getCartData($postData,0,0);
$cartList = $this->Webservice_model->getCartData($postData,$page_limit,$per_page);
if($result['status'] == 'success'){
$total = count($result['data']);
}
if($total >= $per_page){
$totalPages = (int)($total%$per_page == 0?$total/$per_page:($total/$per_page)+1);
}
else{
$totalPages = 1;
}
if($cartList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => $cartList['data'],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}else{
$respArr = array(
'status' => 'error',
'message'=>'No data',
'data' => [],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
public function removeCartPrdt(){
header('Content-type:application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$result = $this->Webservice_model->removeCartPrdt($postData);
echo json_encode($result);exit;
}
public function addToCart(){
header('Content-type:application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$result = $this->Webservice_model->addToCart($postData);
echo json_encode($result);exit;
}
public function add_to_cart(){
header('Content-type:application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$postData['customer_id'] = $authRes['data']['customer_id'];
$result = $this->Webservice_model->addToCart($postData);
echo json_encode($result);exit;
}
public function remove_product(){
header('Content-type:application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$result = $this->Webservice_model->removeCartPrdt($postData);
echo json_encode($result);exit;
}
public function cart_details(){
header('Content-type:application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = "error";
$respArr['message'] = "Authtoken is Required";
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$result = $this->Webservice_model->cart_details();
echo json_encode($result);exit;
}
} }
......
...@@ -664,10 +664,19 @@ class Webservice_model extends CI_Model { ...@@ -664,10 +664,19 @@ class Webservice_model extends CI_Model {
$page = (isset($postData['page']) && $postData['page'] != 1) ?$postData['page'] :'1'; $page = (isset($postData['page']) && $postData['page'] != 1) ?$postData['page'] :'1';
$page_limit = ($page - 1) * $per_page; $page_limit = ($page - 1) * $per_page;
$sql = "SELECT ROUND(AVG(REV.rating),2) AS rating, COUNT(REV.id) AS count,PRD.*,PRDB.brand_name $cartSel = '';
$cartJoin = '';
if(isset($postData['user_id']) && !empty($postData['user_id'])){
$cartSel = ',CRT.cart_id';
$cartJoin = "LEFT JOIN cart AS CRT ON
(CRT.product_id=PRD.product_id AND CRT.customer_id=".$postData['user_id'].")";
}
$sql = "SELECT ROUND(AVG(REV.rating),2) AS rating, COUNT(REV.id) AS count,PRD.*,PRDB.brand_name".
$cartSel."
FROM products AS PRD FROM products AS PRD
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
LEFT JOIN product_brand AS PRDB ON PRDB.brand_id = PRD.brand_id LEFT JOIN product_brand AS PRDB ON PRDB.brand_id = PRD.brand_id
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id ".$cartJoin."
WHERE PRD.product_id =".$postData['product_id']; WHERE PRD.product_id =".$postData['product_id'];
$this->db->query($sql); $this->db->query($sql);
...@@ -675,6 +684,7 @@ class Webservice_model extends CI_Model { ...@@ -675,6 +684,7 @@ class Webservice_model extends CI_Model {
if(!empty($result) && $result->num_rows() > 0){ if(!empty($result) && $result->num_rows() > 0){
$respArr['status'] = 'success'; $respArr['status'] = 'success';
$respArr['data'] = $result->row(); $respArr['data'] = $result->row();
$respArr['data']->rating = (float)$respArr['data']->rating;
$prdt_img = $this->db->get_where('product_images',array('product_id'=>$postData['product_id'],'status'=>'1'))->result(); $prdt_img = $this->db->get_where('product_images',array('product_id'=>$postData['product_id'],'status'=>'1'))->result();
$review = $this->getReviewCount($postData['product_id'],0,0); $review = $this->getReviewCount($postData['product_id'],0,0);
...@@ -902,7 +912,7 @@ class Webservice_model extends CI_Model { ...@@ -902,7 +912,7 @@ class Webservice_model extends CI_Model {
$lmt .= "LIMIT $start,$per_page"; $lmt .= "LIMIT $start,$per_page";
} }
$result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating, $result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.*,PI.image as product_image COUNT(REV.id) AS reviews,PRD.*,PI.image as product_image,BRND.brand_name
FROM products AS PRD FROM products AS PRD
LEFT JOIN product_images AS PI ON LEFT JOIN product_images AS PI ON
(PI.id=(SELECT MIN(id) (PI.id=(SELECT MIN(id)
...@@ -910,14 +920,19 @@ class Webservice_model extends CI_Model { ...@@ -910,14 +920,19 @@ class Webservice_model extends CI_Model {
WHERE product_id= PRD.product_id AND WHERE product_id= PRD.product_id AND
PRD.status='1')) PRD.status='1'))
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
JOIN product_brand AS BRND ON BRND.brand_id = PRD.brand_id
WHERE PRD.status='1' WHERE PRD.status='1'
GROUP BY PRD.product_id,PI.product_id GROUP BY PRD.product_id,PI.product_id
ORDER BY PRD.product_id DESC ORDER BY PRD.product_id DESC
$lmt"); $lmt");
if(!empty($result) && $result->num_rows() > 0){ if(!empty($result) && $result->num_rows() > 0){
$result = $result->result_array();
foreach ($result as $key => $value) {
$result[$key]['rating'] = (float)$value['rating'];
}
$respArr['status'] = 'success'; $respArr['status'] = 'success';
$respArr['message'] = 'success'; $respArr['message'] = 'success';
$respArr['data'] = $result->result_array(); $respArr['data'] = $result;
} }
return $respArr; return $respArr;
} }
...@@ -933,7 +948,7 @@ class Webservice_model extends CI_Model { ...@@ -933,7 +948,7 @@ class Webservice_model extends CI_Model {
if(!empty($sql) && $sql->num_rows() > 0){ if(!empty($sql) && $sql->num_rows() > 0){
foreach ($sql->result_array() as $key => $value) { foreach ($sql->result_array() as $key => $value) {
$result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating, $result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.*,PI.image as product_image COUNT(REV.id) AS reviews,PRD.*,PI.image as product_image,BRND.brand_name
FROM products AS PRD FROM products AS PRD
LEFT JOIN product_images AS PI ON LEFT JOIN product_images AS PI ON
(PI.id=(SELECT MIN(id) (PI.id=(SELECT MIN(id)
...@@ -941,9 +956,12 @@ class Webservice_model extends CI_Model { ...@@ -941,9 +956,12 @@ class Webservice_model extends CI_Model {
WHERE product_id= PRD.product_id AND WHERE product_id= PRD.product_id AND
PRD.status='1')) PRD.status='1'))
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
JOIN product_brand AS BRND ON BRND.brand_id = PRD.brand_id
WHERE PRD.status='1' AND PRD.product_id =".$value['product_id']); WHERE PRD.status='1' AND PRD.product_id =".$value['product_id']);
if(!empty($result) && $result->num_rows() > 0){ if(!empty($result) && $result->num_rows() > 0){
$new_array[$key] = $result->row_array(); $result = $result->row_array();
$result['rating'] = (float)$result['rating'];
$new_array[$key] = $result;
} }
} }
$respArr['status'] = 'success'; $respArr['status'] = 'success';
...@@ -998,5 +1016,66 @@ class Webservice_model extends CI_Model { ...@@ -998,5 +1016,66 @@ class Webservice_model extends CI_Model {
return $respArr; return $respArr;
} }
public function getCartData($postData,$start='',$per_page=''){
$respArr = array('status'=>'error');
if(empty($postData['customer_id'])){
$respArr['message'] = "Customer Id is Required";
return $respArr;
}
$lmt = '';
if($start != 0 || $per_page != 0){
$lmt .= "LIMIT $start,$per_page";
}
$result = $this->db->query("SELECT PRD.product_name,PRD.short_description,CRT.cart_id,CRT.quantity
,CRT.product_id,PI.image as product_image,BRND.brand_name,PRD.amount
FROM cart CRT
JOIN products PRD ON CRT.product_id = PRD.product_id
JOIN product_brand BRND ON BRND.brand_id = PRD.brand_id
LEFT JOIN product_images AS PI ON (PI.id=
(SELECT MIN(id)
FROM product_images
WHERE product_id= PRD.product_id AND
PRD.status='1'))
WHERE CRT.customer_id=".$postData['customer_id']." ORDER BY CRT.cart_id DESC $lmt");
if(empty($result) || empty($result = $result->result())){
$respArr['status'] = "error";
return $respArr;
}
$respArr['status'] = "success";
$respArr['data'] = $result;
return $respArr;
}
public function removeCartPrdt($postData){
$respArr = array('status'=>'error');
if(empty($postData['cart_id'])){
$respArr['message'] = "Cart Id is Required";
return $respArr;
}
if($this->db->delete('cart',array('cart_id'=>$postData['cart_id']))){
$respArr['status'] = "success";
}
return $respArr;
}
public function addToCart($postData){
$respArr = array('status'=>'error');
if(empty($postData)){
$respArr['message'] = "All Field is Required";
return $respArr;
}
$postData['created_date'] = date('Y-m-d h:i:s');
if($this->db->insert('cart',$postData)){
$respArr['data'] = $this->db->insert_id();
$respArr['status'] = 'success';
}
return $respArr;
}
} }
?> ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment