Пример #1
0
 public function actionPairingProducts()
 {
     if (Yii::$app->request->isAjax) {
         /* @var StoreProduct $storeProduct */
         $storeProduct = new StoreProduct();
         $storeProduct->store_id = $_POST['storeId'];
         $storeProduct->product_id = $_POST['productId'];
         $storeProduct->price = $_POST['price'];
         if ($storeProduct->save()) {
             return 'save :)';
         } else {
             return 'not save :(';
         }
     } else {
         $dataProvider = new ActiveDataProvider(['query' => Product::find()]);
         return $this->render('pairing-products', ['dataProvider' => $dataProvider]);
     }
 }
 /**
  * Finds the StoreProduct model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return StoreProduct the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = StoreProduct::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }