public function actionView($id) { $request = Yii::$app->request; $order = Order::findOne($id); if ($order === null) { $this->flash('error', Yii::t('easyii', 'Not found')); return $this->redirect(['/admin/' . $this->module->id]); } if ($request->post('status')) { $newStatus = $request->post('status'); $oldStatus = $order->status; $order->status = $newStatus; $order->remark = filter_var($request->post('remark'), FILTER_SANITIZE_STRING); if ($order->save()) { if ($newStatus != $oldStatus && $request->post('notify')) { $order->notifyUser(); } $this->flash('success', Yii::t('easyii/shopcart', 'Order updated')); } else { $this->flash('error', Yii::t('easyii', 'Update error. {0}', $order->formatErrors())); } return $this->refresh(); } else { if ($order->new > 0) { $order->new = 0; $order->update(); } $goods = Good::find()->where(['order_id' => $order->primaryKey])->with('item')->asc()->all(); return $this->render('view', ['order' => $order, 'goods' => $goods]); } }
public function getGoods() { if (!$this->_goods) { $this->_goods = []; if ($this->id) { foreach (Good::find()->where(['order_id' => $this->id])->with('item')->all() as $good) { $this->_goods[] = new GoodObject($good); } } } return $this->_goods; }