/**
  * Finds the Products model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Products the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Products::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Существует ли товар на складе?
  * @return boolean
  */
 public function getIsProduct()
 {
     $condition = ['kodpart' => $this->kodpart, 'otd' => $this->otd, 'namepr' => $this->dsv];
     $productModel = Products::findOne($condition);
     if (!empty($productModel)) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * добавить продукт к заказу
  * @param type $id - код лр
  * @param type $orderId - ид заказа
  * @return string
  */
 public function actionAddToProductForOrder($id, $orderId)
 {
     $product = Products::findOne(['kodpart' => $id]);
     $model = OrderedProduct::findOne(['kodpart' => $id, 'user_id' => Yii::$app->user->getId(), 'order_id' => $orderId]);
     if (empty($model)) {
         $model = new OrderedProduct();
         $model->kodpart = $product->kodpart;
         $model->imn = $product->tn;
         $model->otd = $product->otd;
         $model->dsv = $product->namepr;
         $model->user_id = Yii::$app->user->getId();
         $model->buggod = true;
     }
     if (Yii::$app->request->isPost) {
         $post = Yii::$app->request->post();
         $model->kolz = (int) $post['kol'];
         if ($model->save()) {
             return $model->kolz;
         }
     } else {
         return 'false';
     }
 }