Commit a75c836c by Jansa Jose

app API

parent 3643f98a
......@@ -2179,21 +2179,288 @@
public function cart_details(){
header('Content-type:application/json');
$headers = apache_request_headers();
$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;
}
$per_page = 10;
$page = (isset($_GET['page']) && $_GET['page'] >= 1)?(int)$_GET['page']:1;
$start = ($page - 1) * $per_page;
$postData['customer_id'] = $authRes['data']['customer_id'];
$cartResult = $this->Webservice_model->getCartData($postData,0,0);
$cartList = $this->Webservice_model->getCartData($postData,$start,$per_page);
$product = array();
$total = 0;
if($cartResult['status'] == 'success'){
$total = count($cartResult['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' => array(
'cart_products' => $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' => array(
'cart_products' => []
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = "error";
$respArr['message'] = "Authtoken is Required";
echo json_encode($respArr);exit;
}
public function my_order_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;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$per_page = 10;
$page = (isset($_GET['page']) && $_GET['page'] >= 1)?(int)$_GET['page']:1;
$start = ($page - 1) * $per_page;
$postData['customer_id'] = $authRes['data']['customer_id'];
$orderResult = $this->Webservice_model->getMyOrders($postData,0,0);
$orderList = $this->Webservice_model->getMyOrders($postData,$start,$per_page);
$product = array();
$total = 0;
if($orderResult['status'] == 'success'){
$total = count($orderResult['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($orderList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => array(
'order_details' => $orderList['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' => array(
'order_details' => []
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
$result = $this->Webservice_model->cart_details();
echo json_encode($result);exit;
public function search_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;
}
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] >= 1)?(int)$postData['page']:1;
$start = ($page - 1) * $per_page;
$searchResult = $this->Webservice_model->productSearch($postData,0,0);
$searchList = $this->Webservice_model->productSearch($postData,$start,$per_page);
$product = array();
$total = 0;
if($searchResult['status'] == 'success'){
$total = count($searchResult['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($searchList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => array(
'search_products' => $searchList['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' => array(
'search_products' => []
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
public function filter_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;
}
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] >= 1)?(int)$postData['page']:1;
$start = ($page - 1) * $per_page;
$filterResult = $this->Webservice_model->productSearch($postData,0,0);
$filterList = $this->Webservice_model->productSearch($postData,$start,$per_page);
$product = array();
$total = 0;
if($filterResult['status'] == 'success'){
$total = count($filterResult['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($filterList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => array(
'sorted_products' => $filterList['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' => array(
'sorted_products' => []
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
}
......
......@@ -634,8 +634,12 @@ class Webservice_model extends CI_Model {
GROUP BY PRD.product_id,PI.product_id
$lmt ");
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['data'] = $result->result_array();
$respArr['data'] = $result;
}
return $respArr;
}
......@@ -865,7 +869,7 @@ class Webservice_model extends CI_Model {
}
$result = $this->db->query("SELECT TRANS.datetime,TRANS.amount,TRANS.status,PRD.product_id,
PRD.product_name,PRD.short_description,ORDS.format_order_id,ORDS.quantity,ORDS.expected_delivery,ORDS.delivered,ORDS.status AS odr_status,PRDR.id AS review_id
PRD.product_name,PRD.short_description,PRD.part_id,ORDS.format_order_id,ORDS.quantity,ORDS.expected_delivery,ORDS.delivered,ORDS.status AS odr_status,PRDR.id AS review_id
FROM transaction TRANS
JOIN orders ORDS ON ORDS.order_id = TRANS.booking_id
JOIN products PRD ON PRD.product_id = ORDS.product_id
......@@ -981,22 +985,29 @@ class Webservice_model extends CI_Model {
if($start != 0 || $per_page != 0){
$lmt .= "LIMIT $start,$per_page";
}
$result = $this->db->query("SELECT PRD.product_name,PRD.short_description,TRANS.id AS transId,
$result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.product_name,PRD.short_description,PRD.part_id,TRANS.id AS transId,
TRANS.status AS tranStatus,TRANS.datetime,ORD.*,PI.image as product_image
FROM orders ORD
JOIN products PRD ON ORD.product_id = PRD.product_id
JOIN transaction TRANS ON (ORD.order_id = TRANS.booking_id AND TRANS.payment_for= '2')
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_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 ORD.customer_id=".$postData['customer_id']." ORDER BY ORD.order_id DESC $lmt");
WHERE ORD.customer_id=".$postData['customer_id']." GROUP BY ORD.order_id ORDER BY ORD.order_id DESC $lmt");
if(empty($result) || empty($result = $result->result())){
$respArr['status'] = "error";
return $respArr;
}
foreach ($result as $key => $value) {
$result[$key]->rating = (float)$value->rating;
}
$respArr['status'] = "success";
$respArr['data'] = $result;
return $respArr;
......@@ -1027,23 +1038,28 @@ class Webservice_model extends CI_Model {
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
$result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.product_name,PRD.short_description,PRD.part_id,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_rating AS REV ON REV.product_id = PRD.product_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");
WHERE CRT.customer_id=".$postData['customer_id']." GROUP BY CRT.cart_id ORDER BY CRT.cart_id DESC $lmt");
if(empty($result) || empty($result = $result->result())){
$respArr['status'] = "error";
return $respArr;
}
foreach ($result as $key => $value) {
$result[$key]->rating = (float)$value->rating;
}
$respArr['status'] = "success";
$respArr['data'] = $result;
return $respArr;
......
......@@ -56,6 +56,13 @@
data-parsley-pattern="^[a-zA-Z0-9\ . _ @ \/]+$" placeholder="Enter Short Description"><?= (isset($product_data->short_description))?$product_data->short_description:'' ?></textarea>
<span class="glyphicon form-control-feedback"></span>
</div>
<div class="form-group">
<label>Part ID</label>
<input type="text" class="form-control" data-parsley-trigger="change" data-parsley-minlength="2" name="part_id"
placeholder="Enter Part ID" value="<?= (isset($product_data->part_id))?$product_data->part_id:'' ?>">
<span class="glyphicon form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
......
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