/** * @param $node * @return string * @throws NotFoundHttpException */ public function actionList($node) { $category = Category::findOne($node); if (!$category) { throw new NotFoundHttpException(); } $model = new ProductSearch(); $dataProvider = $model->search(\Yii::$app->request->queryParams); return $this->render('list', ['dataProvider' => $dataProvider, 'searchModel' => $model, 'category' => $category]); }
/** * Updates an existing Product model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionMinius($id) { // echo Url::toRoute(['admin/product/minius', 'id' => $id]); $searchModel = new ProductSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $LogModel = new log(); $LogModel->product_id = $id; $LogModel->number = -1; $model = $this->findModel($id); $LogModel->content = "đã bán sản phẩm " . $model->name . " với số lượng là "; $LogModel->save(); if ($model->number != 0) { $model->number--; } else { echo "<script>alert('không thể thực hiện vì số lượng đã bằng 0');</script>"; } $model->save(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } else { return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } }
/** * Lists all Product models. * @return mixed */ public function actionIndex() { $searchModel = new ProductSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }