[ 'class' => 'yii\web\ErrorAction', ], ]; } /** * @inheritdoc */ public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'feedback' => [ 'post' ], ], ], ]; } /** * Displays homepage. * * @return mixed */ public function actionIndex() { /** * @var \artbox\core\components\SeoComponent $seo */ $seo = \Yii::$app->get('seo'); $seo->setAlias( new DummyAlias( [ 'title' => \Yii::t('app', 'Главная страница'), ] ) ); $categories = Category::find() ->with('categories.lang', 'lang') ->where([ 'level' => 0 ]) ->all(); $topItems = Product::find() ->with('lang.alias', 'image', 'variants') ->is('mask', 1) ->limit(20) ->all(); $newItems = Product::find() ->with('lang.alias', 'image', 'variants') ->is('mask', 2) ->limit(20) ->all(); $saleItems = Product::find() ->with('lang.alias', 'image', 'variants') ->is('mask', 4) ->limit(20) ->all(); $productCount = Product::find() ->count(); $brandCount = Brand::find() ->count(); $brands = Brand::find() ->joinWith('lang') ->where([ 'status' => true ]) ->andWhere( [ 'not', [ 'image_id' => null ], ] ) ->orderBy( [ 'sort' => SORT_ASC, 'title' => SORT_ASC, ] ) ->limit(6) ->with('image') ->all(); $articles = Article::find() ->orderBy('sort') ->with( [ 'lang', 'image', 'category.lang', ] ) ->limit(4) ->all(); $slider = Slider::find() ->with('image') ->where([ 'status' => true ]) ->orderBy( [ 'sort' => SORT_ASC, ] ) ->all(); return $this->render( 'index', [ 'categories' => $categories, 'topItems' => $topItems, 'newItems' => $newItems, 'saleItems' => $saleItems, 'productCount' => $productCount, 'brandCount' => $brandCount, 'brands' => $brands, 'articles' => $articles, 'slider' => $slider, ] ); } /** * Displays contact page. * * @return mixed */ public function actionContact() { $contact = new Feedback(); return $this->render( 'contact', [ 'contact' => $contact, ] ); } /** * Displays about page. * * @return mixed */ public function actionAbout() { return $this->render('about'); } /** * Action to view robots.txt file dinamycli * * @return string */ public function actionRobots() { $response = \Yii::$app->response; /** * @var Settings $settings */ $settings = Settings::find() ->one(); $temp = tmpfile(); fwrite($temp, $settings->robots); $meta = stream_get_meta_data($temp); $response->format = $response::FORMAT_RAW; $response->headers->set('Content-Type', 'text/plain'); return $this->renderFile($meta[ 'uri' ]); } public function actionFeedback() { Yii::$app->response->format = Response::FORMAT_JSON; if (empty(Yii::$app->request->post())) { throw new BadRequestHttpException(); } else { $model = new Feedback( [ 'scenario' => Feedback::SCENARIO_CONTACT, ] ); if ($model->load(Yii::$app->request->post()) && $model->save()) { die(var_dump($model)); return [ 'success' => true, 'message' => \Yii::t('app', 'Заявка успешно отправлена'), 'alert' => '
' . \Yii::t( 'app', 'Спасибо, Ваша заявка успешно отправлена. Наши менеджеры свяжутся с Вами в ближайшее время' ) . '