Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dcarfixers
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tobin
dcarfixers
Commits
3643f98a
Commit
3643f98a
authored
Jun 03, 2019
by
Jansa Jose
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webservices for web and app
parent
59ba94a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
226 additions
and
13 deletions
+226
-13
Product.php
application/controllers/Product.php
+6
-6
Webservices.php
application/controllers/Webservices.php
+134
-0
Webservice_model.php
application/models/Webservice_model.php
+86
-7
No files found.
application/controllers/Product.php
View file @
3643f98a
...
...
@@ -57,7 +57,7 @@ class Product extends CI_Controller {
$flashMsg
=
array
(
'message'
=>
'Something went wrong, please try again..!'
,
'class'
=>
'error'
);
if
(
!
isset
(
$_POST
)
||
empty
(
$_POST
)){
$this
->
session
->
set_flashdata
(
'message'
,
$flashMsg
);
redirect
(
base_url
(
'Product/add
P
roduct'
));
redirect
(
base_url
(
'Product/add
p
roduct'
));
}
if
(
$err
==
0
&&
(
!
isset
(
$_POST
[
'brand_id'
])
||
empty
(
$_POST
[
'brand_id'
]))){
$err
=
1
;
...
...
@@ -91,7 +91,7 @@ class Product extends CI_Controller {
if
(
$err
==
1
){
$flashMsg
[
'message'
]
=
$errMsg
;
$this
->
session
->
set_flashdata
(
'message'
,
$flashMsg
);
redirect
(
base_url
(
'Product/add
P
roduct'
));
redirect
(
base_url
(
'Product/add
p
roduct'
));
}
$product_id
=
$this
->
Product_model
->
addProduct
(
$_POST
);
...
...
@@ -125,7 +125,7 @@ class Product extends CI_Controller {
redirect
(
base_url
(
'Product/viewProducts'
));
}
else
{
$this
->
session
->
set_flashdata
(
'message'
,
$flashMsg
);
redirect
(
base_url
(
'Product/add
P
roduct'
));
redirect
(
base_url
(
'Product/add
p
roduct'
));
}
}
}
...
...
@@ -137,7 +137,7 @@ class Product extends CI_Controller {
redirect
(
base_url
(
'Product/viewProducts'
));
}
$template
[
'page'
]
=
'Product/add
P
roduct'
;
$template
[
'page'
]
=
'Product/add
p
roduct'
;
$template
[
'menu'
]
=
'Brand Management'
;
$template
[
'smenu'
]
=
'Edit brand'
;
$template
[
'pTitle'
]
=
"Edit brand"
;
...
...
@@ -162,7 +162,7 @@ class Product extends CI_Controller {
}
if
(
!
isset
(
$_POST
)
||
empty
(
$_POST
)){
$this
->
session
->
set_flashdata
(
'message'
,
$flashMsg
);
redirect
(
base_url
(
'Product/add
P
roduct'
));
redirect
(
base_url
(
'Product/add
p
roduct'
));
}
if
(
$err
==
0
&&
(
!
isset
(
$_POST
[
'brand_id'
])
||
empty
(
$_POST
[
'brand_id'
]))){
$err
=
1
;
...
...
@@ -196,7 +196,7 @@ class Product extends CI_Controller {
if
(
$err
==
1
){
$flashMsg
[
'message'
]
=
$errMsg
;
$this
->
session
->
set_flashdata
(
'message'
,
$flashMsg
);
redirect
(
base_url
(
'Product/add
P
roduct'
));
redirect
(
base_url
(
'Product/add
p
roduct'
));
}
$existingImages
=
(
isset
(
$_POST
[
'existingImages'
])
&&
!
empty
(
$_POST
[
'existingImages'
]))
?
$_POST
[
'existingImages'
]
:
''
;
...
...
application/controllers/Webservices.php
View file @
3643f98a
...
...
@@ -2061,6 +2061,140 @@
$result
=
$this
->
Webservice_model
->
cancelOrder
(
$postData
);
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
;
}
}
...
...
application/models/Webservice_model.php
View file @
3643f98a
...
...
@@ -664,10 +664,19 @@ class Webservice_model extends CI_Model {
$page
=
(
isset
(
$postData
[
'page'
])
&&
$postData
[
'page'
]
!=
1
)
?
$postData
[
'page'
]
:
'1'
;
$page_limit
=
(
$page
-
1
)
*
$per_page
;
$sql
=
"SELECT ROUND(AVG(REV.rating),2) AS rating, COUNT(REV.id) AS count,PRD.*,PRDB.brand_name
FROM products AS PRD
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
$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
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'
];
$this
->
db
->
query
(
$sql
);
...
...
@@ -675,6 +684,7 @@ class Webservice_model extends CI_Model {
if
(
!
empty
(
$result
)
&&
$result
->
num_rows
()
>
0
){
$respArr
[
'status'
]
=
'success'
;
$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
();
$review
=
$this
->
getReviewCount
(
$postData
[
'product_id'
],
0
,
0
);
...
...
@@ -902,7 +912,7 @@ class Webservice_model extends CI_Model {
$lmt
.=
"LIMIT
$start
,
$per_page
"
;
}
$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
LEFT JOIN product_images AS PI ON
(PI.id=(SELECT MIN(id)
...
...
@@ -910,14 +920,19 @@ class Webservice_model extends CI_Model {
WHERE product_id= PRD.product_id AND
PRD.status='1'))
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'
GROUP BY PRD.product_id,PI.product_id
ORDER BY PRD.product_id DESC
$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
[
'message'
]
=
'success'
;
$respArr
[
'data'
]
=
$result
->
result_array
()
;
$respArr
[
'data'
]
=
$result
;
}
return
$respArr
;
}
...
...
@@ -933,7 +948,7 @@ class Webservice_model extends CI_Model {
if
(
!
empty
(
$sql
)
&&
$sql
->
num_rows
()
>
0
){
foreach
(
$sql
->
result_array
()
as
$key
=>
$value
)
{
$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
LEFT JOIN product_images AS PI ON
(PI.id=(SELECT MIN(id)
...
...
@@ -941,9 +956,12 @@ class Webservice_model extends CI_Model {
WHERE product_id= PRD.product_id AND
PRD.status='1'))
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'
]);
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'
;
...
...
@@ -997,6 +1015,67 @@ class Webservice_model extends CI_Model {
}
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
;
}
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment