-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
395 lines (307 loc) · 14.6 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'http://localhost/tiendaw',
'ck_3daf0e70f259318be83947aa8944676db667e2b3',
'cs_4d65524bef39f6e436f87ee8a098c7dd56731422',
[
'version' => 'wc/v3',
]
);
//$products = $woocommerce->get('products');
try {
$results = $woocommerce->get('orders');
$products = $woocommerce->get('products');
$customers = $woocommerce->get('customers');
$result = count($results);
$customer = count($customers);
$product = count($products);
$query = ['date_min' => '2019-09-01', 'date_max' => '2019-09-20'];
$sales = $woocommerce->get('reports/sales', $query);
$sale = $sales[0]->total_sales;
// Last request data.
$lastRequest = $woocommerce->http->getRequest();
$lastRequest->getUrl(); // Requested URL (string).
$lastRequest->getMethod(); // Request method (string).
$lastRequest->getParameters(); // Request parameters (array).
$lastRequest->getHeaders(); // Request headers (array).
$lastRequest->getBody(); // Request body (JSON).
// Last response data.
$lastResponse = $woocommerce->http->getResponse();
$lastResponse->getCode(); // Response code (int).
$lastResponse->getHeaders(); // Response headers (array).
$lastResponse->getBody(); // Response body (JSON).
}
catch(HttpClientException $e) {
$e->getMessage(); // Error message.
$e->getRequest(); // Last request data.
$e->getResponse(); // Last response data.
}
if (isset($_POST['btn-update'])) {
$status = $_POST['bookId'];
$st = $_POST['ostatus'];
$woocommerce->put('orders/' . $status, array(
'status' => $st
));
header('Location: https://shahroznawaz.com/woo');
}
if (isset($_POST['btn-delete'])) {
$oid = $_POST['cId'];
$woocommerce->delete('orders/' . $oid, ['force' => true]);
header('Location: https://shahroznawaz.com/woo');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>Dashboard Template for Bootstrap</title>
</head>
<div class="container">
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-1">
<h1 class="page-header">Dashboard</h1>
<div class="row placeholders">
<div class="col-xs-6 col-sm-3 placeholder">
<p id="large">
<?php echo $result?>
</p>
<hr>
<span class="text-muted">New Orders</span>
</div>
<div class="col-xs-6 col-sm-3 placeholder">
<p id="large">
<?php echo $customer?>
</p>
<hr>
<span class="text-muted">Customers</span>
</div>
<div class="col-xs-6 col-sm-3 placeholder">
<p id="large">
<?php echo $product?>
</p>
<hr>
<span class="text-muted">All Products</span>
</div>
<div class="col-xs-6 col-sm-3 placeholder">
<p id="large">
<?php echo $sale?>
</p>
<hr>
<span class="text-muted">Total Sales</span>
</div>
</div>
</div>
</div>
<div class="container">
<h2 class="sub-header">Orders List</h2>
<div class='table-responsive'>
<table id='myTable' class='table table-striped table-bordered'>
<thead>
<tr>
<th>Order #</th>
<th>Customer</th>
<th>Address</th>
<th>Contact</th>
<th>Order Date</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
foreach($results as $details){
echo "<tr><td>" . $details->id."</td>
<td>" . $details->billing->first_name.$details->billing->last_name."</td>
<td>" . $details->shipping->address_1."</td>
<td>" . $details->billing->phone."</td>
<td>" . $details->date_created."</td>
<td>" . $details->status."</td>
<td><a class='open-AddBookDialog btn btn-primary' data-target='#myModal' data-id=".$details->id." data-toggle='modal'>Update</a>
<a class='open-deleteDialog btn btn-danger' data-target='#myModal1' data-id=".$details->id." data-toggle='modal'>Delete</a></td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
<div class="container">
<h2 class="sub-header">Customers List</h2>
<div class='table-responsive'>
<table id='myTable' class='table table-striped table-bordered'>
<thead>
<tr>
<th>Email</th>
<th>Name</th>
<th>Billing Address</th>
<th>Total Orders</th>
<th>Total spent</th>
<th>Avatar</th>
</tr>
</thead>
<tbody>
<?php
foreach($customers as $customer){
echo "<tr><td>" . $customer->email."</td>
<td>" . $customer->first_name.$customer->last_name."</td>
<td>" . $customer->billing->address_1."</td>
<td>" . $customer->orders_count."</td>
<td>" . $customer->total_spent."</td>
<td><img height='50px' width='50px' src='".$customer->avatar_url."'></td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
<div class="container">
<h2 class="sub-header">Products List</h2>
<div class='table-responsive'>
<table id='myTable' class='table table-striped table-bordered'>
<thead>
<tr>
<th>SKU</th>
<th>Name</th>
<th>Status</th>
<th>Price</th>
<th>Total Sales</th>
<th>Picture</th>
</tr>
</thead>
<tbody>
<?php
foreach($products as $product){
echo "<tr><td>" . $product->sku."</td>
<td>" . $product->name."</td>
<td>" . $product->status."</td>
<td>" . $product->price."</td>
<td>" . $product->total_sales."</td>
<td><img height='50px' width='50px' src='".$product->images[0]->src."'></td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Update Order Status</h4>
</div>
<div class="modal-body">
<p>Order ID:</p>
<form action="" method="post">
<div class="form-group">
<input type="text" class="form-control" name="bookId" id="bookId" value="">
<p for="sel1">Select list (select one):</p>
<select class="form-control" id="status" name="ostatus">
<option>Pending Payment</option>
<option>processing</option>
<option>On Hold</option>
<option>completed</option>
<option>Cancelled</option>
<option>Refunded</option>
<option>Failed</option>
</select>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-block" name="btn-update">Update</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="myModal1" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Confirm Order Deletion</h4>
</div>
<div class="modal-body">
<p>Really you want to delete order?</p>
<form action="" method="post">
<div class="form-group">
<input type="text" class="form-control" name="cId" id="cId" value="">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger" name="btn-delete">Delete</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
$(document).on("click", ".open-AddBookDialog", function() {
var myBookId = $(this).data('id');
$(".modal-body #bookId").val(myBookId);
});
</script>
<script>
$(document).on("click", ".open-deleteDialog", function() {
var myBook = $(this).data('id');
$(".modal-body #cId").val(myBook);
});
</script>
</body>
</html>
<!--<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li>
<li><a href="#">Reports</a></li>
<li><a href="#">Analytics</a></li>
<li><a href="#">Export</a></li>
</ul>
<ul class="nav nav-sidebar">
<li><a href="">Nav item</a></li>
<li><a href="">Nav item again</a></li>
<li><a href="">One more nav</a></li>
<li><a href="">Another nav item</a></li>
<li><a href="">More navigation</a></li>
</ul>
<ul class="nav nav-sidebar">
<li><a href="">Nav item again</a></li>
<li><a href="">One more nav</a></li>
<li><a href="">Another nav item</a></li>
</ul>
</div>-->
<!--<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Dashboard</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Help</a></li>
</ul>
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form>
</div>
</div>
</nav>-->