Skip to content

Commit b8981b6

Browse files
committed
order status tracking and update
1 parent bccdc91 commit b8981b6

30 files changed

+550
-36
lines changed

.DS_Store

2 KB
Binary file not shown.

app/.DS_Store

0 Bytes
Binary file not shown.

app/Http/.DS_Store

2 KB
Binary file not shown.

app/Http/Controllers/AdminController.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,21 @@ public function uploadPP(Request $request){
8585

8686
public function saveCategory(Request $request){
8787
$cat_name = $request->cat_name;
88+
$id = $request->id;
89+
if(isset($id)){
90+
$add_cat = DB::table('cats')->where('id',$id)
91+
->update([
92+
'cat_name' => $cat_name,
93+
'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
94+
'updated_at' => \Carbon\Carbon::now()->toDateTimeString(),
8895

96+
]);
97+
if($add_cat){
98+
echo "done";
99+
}else{
100+
echo "error";
101+
}
102+
}else{
89103
$add_cat = DB::table('cats')->insert([
90104
'cat_name' => $cat_name,
91105
'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
@@ -98,6 +112,7 @@ public function saveCategory(Request $request){
98112
echo "error";
99113
}
100114
}
115+
}
101116

102117
public function banUser(Request $request){
103118
//return $request->all();
@@ -112,9 +127,33 @@ public function banUser(Request $request){
112127
if($update_status){
113128
echo "status updated successfully";
114129
}
130+
}
115131

116132

117-
}
133+
public function orders(){
134+
$orders = DB::table('orders')
135+
->Select('users.name as username','users.id as userId',
136+
'orders.id','orders.status','orders.total','orders.created_at')
137+
->leftJoin('users', 'users.id', 'orders.user_id')
138+
->orderBy('orders.id','DESC')
139+
->get();
140+
return view('admin.orders',compact('orders'));
141+
}
142+
143+
public function orderStatusUpdate(Request $request){
144+
if(isset($request->order_id) && isset($request->order_status)){
145+
//save order status
146+
$uptStatus =DB::table('orders')->where('id',$request->order_id)
147+
->update(['status' => $request->order_status]);
148+
149+
if($uptStatus){
150+
echo "Order " . $request->order_status;
151+
}
152+
else{
153+
echo "error";
154+
}
155+
}
156+
}
118157

119158

120159

app/Http/Kernel.php

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ class Kernel extends HttpKernel
5757
'can' => \Illuminate\Auth\Middleware\Authorize::class,
5858
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
5959
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
60+
'admin' => \App\Http\Middleware\admin::class,
6061
];
6162
}

app/Http/Middleware/admin.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Support\Facades\Auth;
7+
class admin
8+
{
9+
/**
10+
* Handle an incoming request.
11+
*
12+
* @param \Illuminate\Http\Request $request
13+
* @param \Closure $next
14+
* @return mixed
15+
*/
16+
public function handle($request, Closure $next)
17+
{
18+
if(Auth::check() && Auth::user()->isRole()=="admin")
19+
{
20+
return $next($request);
21+
}
22+
return redirect('login'); // if this is not admin the redirect to login
23+
}
24+
}

app/orders.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ public static function createOrder(){
3030

3131
Cart::destroy(); // make cart empty
3232
}
33+
34+
35+
public function orders_products(){
36+
return $this->hasMany('App\orders_products', 'orders_id');
37+
}
3338
}

app/orders_products.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class orders_products extends Model
8+
{
9+
//
10+
}

composer.json

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"require": {
88
"php": ">=7.0.0",
99
"fideloper/proxy": "~3.3",
10+
"gloudemans/shoppingcart": "^2.4",
1011
"laravel/framework": "5.5.*",
1112
"laravel/tinker": "~1.0"
1213
},

composer.lock

100644100755
Lines changed: 61 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database/.DS_Store

6 KB
Binary file not shown.

database/seeds/DatabaseSeeder.php

100644100755
File mode changed.

resources/.DS_Store

0 Bytes
Binary file not shown.

resources/views/.DS_Store

0 Bytes
Binary file not shown.

resources/views/admin/master.blade.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@
3232
<link href="{{Config::get('app.url')}}/admin_theme/assets/css/pe-icon-7-stroke.css" rel="stylesheet" />
3333
<script src="{{Config::get('app.url')}}/admin_theme/assets/js/jquery-1.10.2.js" type="text/javascript"></script>
3434

35-
35+
<style>
36+
.row_head div{ border:1px solid #efefef}
37+
.row_body, .row_head div{
38+
padding:10px;
39+
text-align:center
40+
41+
}
42+
.row_body{ border-bottom:1px solid #efefef}
43+
</style>
3644
</head>
3745
<body>
3846

@@ -64,7 +72,7 @@
6472

6573
<li>
6674
<a href="{{url('/admin/addProduct')}}">
67-
<i class="pe-7s-note2"></i>
75+
<i class="pe-7s-note"></i>
6876
<p>Product</p>
6977
</a>
7078
</li>
@@ -81,8 +89,16 @@
8189
<i class="pe-7s-notebook"></i>
8290
<p>Users</p>
8391
</a>
92+
</li>
93+
94+
<li>
95+
<a href="{{url('/admin/orders')}}">
96+
<i class="pe-7s-note2"></i>
97+
<p>Orders</p>
98+
</a>
8499
</li>
85100

101+
86102
</ul>
87103
</div>
88104
</div>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
@extends('admin.master')
2+
@section('content')
3+
<script>
4+
$(document).ready(function(){
5+
<?php for($i=1;$i<15;$i++){?>
6+
$('#order_status<?php echo $i;?>').change(function(){
7+
var order_id<?php echo $i;?> = $('#order_id<?php echo $i;?>').val();
8+
var order_status<?php echo $i;?> = $('#order_status<?php echo $i;?>').val();
9+
10+
$.ajax({
11+
type: 'get',
12+
data: 'order_id=' + order_id<?php echo $i;?> + '&order_status=' + order_status<?php echo $i;?>,
13+
url: '<?php echo url('admin/orderStatusUpdate');?>',
14+
success: function(response){
15+
console.log(response);
16+
$('#successMsg<?php echo $i;?>').html(response);
17+
}
18+
});
19+
});
20+
<?php }?>
21+
});
22+
</script>
23+
<div class="content">
24+
25+
26+
<div class="card">
27+
<div class="header text-center">
28+
<h4 class="title">Orders</h4>
29+
</div>
30+
<div class="row row_head">
31+
<div class="col-md-2 col-xs-2 col-sm-2"> Order ID</div>
32+
<div class="col-md-2 col-xs-2 col-sm-2"> Date</div>
33+
<div class="col-md-2 col-xs-2 col-sm-2"> User(Id)</div>
34+
<div class="col-md-2 col-xs-2 col-sm-2"> Order Total</div>
35+
<div class="col-md-2 col-xs-2 col-sm-2"> status</div>
36+
<div class="col-md-2 col-xs-2 col-sm-2"> Details</div>
37+
</div>
38+
<?php $countOrder =1;?>
39+
@foreach($orders as $order)
40+
41+
<div class="row row_body">
42+
43+
<div class="col-md-2 col-xs-2 col-sm-2">#{{$order->id}}</div>
44+
<div class="col-md-2 col-xs-2 col-sm-2">
45+
{{date('d M Y', strtotime($order->created_at))}}<br>
46+
{{date('H:i A', strtotime($order->created_at))}}
47+
48+
</div>
49+
50+
<div class="col-md-2 col-xs-2 col-sm-2">{{$order->username}}(#{{$order->userId}})</div>
51+
52+
53+
<div class="col-md-2 col-xs-2 col-sm-2"> {{$order->total}}</div>
54+
55+
<div class="col-md-2 col-xs-2 col-sm-2">
56+
57+
<input type="hidden" id="order_id<?php echo $countOrder;?>" value="{{$order->id}}"/>
58+
<select class="form-control" id="order_status<?php echo $countOrder;?>">
59+
<option value="pending"
60+
<?php if($order->status=='pending'){?> selected="selected"<?php }?>>pending</option>
61+
62+
<option value="dispatched"
63+
<?php if($order->status=='dispatched'){?> selected="selected"<?php }?>>dispatched</option>
64+
65+
<option value="processed"
66+
<?php if($order->status=='processed'){?> selected="selected"<?php }?>>processed</option>
67+
68+
<option value="shipping"
69+
<?php if($order->status=='shipping'){?> selected="selected"<?php }?>>shipping</option>
70+
71+
<option value="cancelled"
72+
<?php if($order->status=='cancelled'){?> selected="selected"<?php }?>>cancelled</option>
73+
74+
<option value="delivered"
75+
<?php if($order->status=='delivered'){?> selected="selected"<?php }?>>delivered</option>
76+
</select>
77+
<div align="center" id="successMsg<?php echo $countOrder;?>"></div>
78+
</div>
79+
80+
<div class="col-md-2 col-xs-2 col-sm-2">
81+
<a href=""><span class="pe-7s-download" style="font-size:40px"></span></a>
82+
</div>
83+
84+
</div>
85+
<?php $countOrder++;?>
86+
@endforeach
87+
88+
</div>
89+
</div>
90+
91+
@endsection

resources/views/front/checkout.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@
5555
<div class="form-group">
5656
<div class="col-md-6">
5757
<!-- First name -->
58-
<input type="text" class="form-control" placeholder="Full name" name="fullname">
58+
<input type="text" class="form-control" placeholder="Full name" name="fullname"
59+
value="{{Auth::user()->name}}">
5960
<span style="color:red">{{ $errors->first('fullname') }}</span>
6061
<br> <br>
61-
<input type="email" class="form-control" placeholder="Email" name="email">
62+
<input type="email" class="form-control" placeholder="Email" name="email"
63+
value="{{Auth::user()->email}}">
6264
<span style="color:red">{{ $errors->first('email') }}</span>
6365
<br> <br>
6466
<input type="text" class="form-control" placeholder="Phone number" name="phone">

0 commit comments

Comments
 (0)