Commit 6628fe31f5e7bcb98c38eab2b03b46119807d2fc

Authored by Alexey Boroda
1 parent c316e881

-User's order page in process

frontend/controllers/AccountController.php
... ... @@ -3,7 +3,10 @@
3 3 namespace frontend\controllers;
4 4  
5 5 use artbox\order\models\Customer;
  6 + use artbox\order\models\Order;
6 7 use yii\web\Controller;
  8 + use yii\web\ForbiddenHttpException;
  9 + use yii\web\NotFoundHttpException;
7 10  
8 11 /**
9 12 * Class AccountController
... ... @@ -14,15 +17,12 @@
14 17 {
15 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 22 $orders = $user->getOrders()
23 23 ->with(
24 24 [
25   - 'label',
  25 + 'label.lang',
26 26 'orderProducts',
27 27 ]
28 28 )
... ... @@ -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 66 \ No newline at end of file
... ...
frontend/views/account/index.php
1 1 <?php
2 2  
3 3 use artbox\order\models\Order;
  4 + use yii\helpers\Url;
4 5 use yii\web\View;
5 6  
6 7 /**
... ... @@ -50,10 +51,23 @@ _________________________________________________________ --&gt;
50 51 <tr>
51 52 <th>№<?= $order->id; ?></th>
52 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 71 </td>
58 72 </tr>
59 73 <?php } ?>
... ...