[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => [ 'POST' ], ], ], ]; } /** * Lists all VariantToShop models. * @param int|null $shop_id * @return mixed */ public function actionIndex($shop_id) { $dataProvider = new ActiveDataProvider( [ 'query' => VariantToShop::find() ->with( [ 'variant', 'variant.lang', 'shop', 'shop.lang', ] ) ->where([ 'shop_id' => $shop_id ]), ] ); return $this->render( 'index', [ 'dataProvider' => $dataProvider, 'shop_id' => $shop_id, ] ); } /** * Displays a single VariantToShop model. * * @param integer $variant_id * @param integer $shop_id * * @return mixed */ public function actionView($variant_id, $shop_id) { return $this->render( 'view', [ 'model' => $this->findModel($variant_id, $shop_id), ] ); } /** * Creates a new VariantToShop model. * If creation is successful, the browser will be redirected to the 'view' page. * @param int|null $shop_id * @return mixed */ public function actionCreate($shop_id) { $model = new VariantToShop(); $shop = Shop::find() ->with([ 'lang' ]) ->where([ 'id' => $shop_id ]) ->one(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect( [ 'view', 'variant_id' => $model->variant_id, 'shop_id' => $model->shop_id, ] ); } else { return $this->render( 'create', [ 'model' => $model, 'shop' => $shop, ] ); } } /** * Updates an existing VariantToShop model. * If update is successful, the browser will be redirected to the 'view' page. * * @param integer $variant_id * @param integer $shop_id * * @return mixed */ public function actionUpdate($variant_id, $shop_id) { $model = $this->findModel($variant_id, $shop_id); $shop = Shop::find() ->with([ 'lang' ]) ->where([ 'id' => $shop_id ]) ->one(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect( [ 'view', 'variant_id' => $model->variant_id, 'shop_id' => $model->shop_id, ] ); } else { return $this->render( 'update', [ 'model' => $model, 'shop' => $shop, ] ); } } /** * Deletes an existing VariantToShop model. * If deletion is successful, the browser will be redirected to the 'index' page. * * @param integer $variant_id * @param integer $shop_id * * @return mixed */ public function actionDelete($variant_id, $shop_id) { $this->findModel($variant_id, $shop_id) ->delete(); return $this->redirect([ 'index' ]); } /** * Finds the VariantToShop model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param integer $variant_id * @param integer $shop_id * * @return VariantToShop the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($variant_id, $shop_id) { if (( $model = VariantToShop::findOne( [ 'variant_id' => $variant_id, 'shop_id' => $shop_id, ] ) ) !== null ) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * @param string $q * @param int|null $shop_id * * @return array */ public function actionList(string $q = null, $shop_id) { \Yii::$app->response->format = Response::FORMAT_JSON; $out = [ 'results' => [ 'id' => '', 'text' => '', ], ]; if (!is_null($q)) { $not = VariantToShop::find() ->select('variant_id') ->where([ 'shop_id' => $shop_id ]); $out[ 'results' ] = Variant::find() ->select( [ 'variant.id as id', 'variant.sku as text', ] ) ->where( [ 'like', 'variant.sku', $q, ] ) ->where( [ 'NOT IN', 'variant.id', $not, ] ) ->limit(20) ->asArray() ->all(); } return $out; } }