Commit 6628fe31f5e7bcb98c38eab2b03b46119807d2fc
1 parent
c316e881
-User's order page in process
Showing
2 changed files
with
45 additions
and
9 deletions
Show diff stats
frontend/controllers/AccountController.php
@@ -3,7 +3,10 @@ | @@ -3,7 +3,10 @@ | ||
3 | namespace frontend\controllers; | 3 | namespace frontend\controllers; |
4 | 4 | ||
5 | use artbox\order\models\Customer; | 5 | use artbox\order\models\Customer; |
6 | + use artbox\order\models\Order; | ||
6 | use yii\web\Controller; | 7 | use yii\web\Controller; |
8 | + use yii\web\ForbiddenHttpException; | ||
9 | + use yii\web\NotFoundHttpException; | ||
7 | 10 | ||
8 | /** | 11 | /** |
9 | * Class AccountController | 12 | * Class AccountController |
@@ -14,15 +17,12 @@ | @@ -14,15 +17,12 @@ | ||
14 | { | 17 | { |
15 | public function actionIndex() | 18 | public function actionIndex() |
16 | { | 19 | { |
17 | - /** | ||
18 | - * @var Customer $user | ||
19 | - */ | ||
20 | - $user = \Yii::$app->user->identity; | 20 | + $user = Customer::findOne(\Yii::$app->user->identity->getId()); |
21 | 21 | ||
22 | $orders = $user->getOrders() | 22 | $orders = $user->getOrders() |
23 | ->with( | 23 | ->with( |
24 | [ | 24 | [ |
25 | - 'label', | 25 | + 'label.lang', |
26 | 'orderProducts', | 26 | 'orderProducts', |
27 | ] | 27 | ] |
28 | ) | 28 | ) |
@@ -40,4 +40,26 @@ | @@ -40,4 +40,26 @@ | ||
40 | ] | 40 | ] |
41 | ); | 41 | ); |
42 | } | 42 | } |
43 | + | ||
44 | + public function actionOrder($id) | ||
45 | + { | ||
46 | + /** | ||
47 | + * @var Order $order | ||
48 | + */ | ||
49 | + $order = Order::find() | ||
50 | + ->with('orderProducts') | ||
51 | + ->where( | ||
52 | + [ | ||
53 | + 'id' => $id, | ||
54 | + ] | ||
55 | + ) | ||
56 | + ->one(); | ||
57 | + | ||
58 | + if (empty($order)) { | ||
59 | + throw new NotFoundHttpException(\Yii::t('app', 'Order not found')); | ||
60 | + } elseif ($order->user_id !== \Yii::$app->user->identity->getId()) { | ||
61 | + throw new ForbiddenHttpException(); | ||
62 | + } | ||
63 | + | ||
64 | + } | ||
43 | } | 65 | } |
44 | \ No newline at end of file | 66 | \ No newline at end of file |
frontend/views/account/index.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | use artbox\order\models\Order; | 3 | use artbox\order\models\Order; |
4 | + use yii\helpers\Url; | ||
4 | use yii\web\View; | 5 | use yii\web\View; |
5 | 6 | ||
6 | /** | 7 | /** |
@@ -50,10 +51,23 @@ _________________________________________________________ --> | @@ -50,10 +51,23 @@ _________________________________________________________ --> | ||
50 | <tr> | 51 | <tr> |
51 | <th>№<?= $order->id; ?></th> | 52 | <th>№<?= $order->id; ?></th> |
52 | <td><?= date('d.m.Y', $order->created_at); ?></td> | 53 | <td><?= date('d.m.Y', $order->created_at); ?></td> |
53 | - <td>150.00</td> | ||
54 | - <td><span class="label label-info">Готовится</span> | ||
55 | - </td> | ||
56 | - <td><a href="customer-order.html" class="btn btn-template-main btn-sm">Посмотреть</a> | 54 | + <td><?= $price ?></td> |
55 | + <?php if (empty($order->label)) { ?> | ||
56 | + <td><span class="label label-info">Не задан</span> | ||
57 | + </td> | ||
58 | + <?php | ||
59 | + } else { ?> | ||
60 | + <td> | ||
61 | + <span style="background-color:<?= $order->label->color ?>" class="label label-info"><?= $order->label->lang->title ?></span> | ||
62 | + </td> | ||
63 | + <?php } | ||
64 | + ?> | ||
65 | + <td><a href="<?= Url::to( | ||
66 | + [ | ||
67 | + 'account/order', | ||
68 | + 'id' => $order->id, | ||
69 | + ] | ||
70 | + ) ?>" class="btn btn-template-main btn-sm">Посмотреть</a> | ||
57 | </td> | 71 | </td> |
58 | </tr> | 72 | </tr> |
59 | <?php } ?> | 73 | <?php } ?> |