render('index', [
        ]);
    }
    /**
     * Logs out the current user.
     *
     * @return mixed
     */
    public function actionLogout()
    {
        Yii::$app->user->logout();
        return $this->goHome();
    }
    /**
     * Logs in a user.
     *
     * @return mixed
     */
    public function actionLogin()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render('index', [
                'model' => $model,
            ]);
        }
    }
    /**
     * Signs user up.
     *
     * @return mixed
     */
    public function actionSignup()
    {
        if(Yii::$app->request->post()){
            if (Yii::$app->request->isAjax) {
                Yii::$app->response->format = Response::FORMAT_JSON;
                $model = new SignupForm();
                $model->load(Yii::$app->request->post());
                return ActiveForm::validate($model);
            } else {
                $model = new SignupForm();
                $model->load(Yii::$app->request->post());
                if ($user = $model->signup()) {
                    if (Yii::$app->getUser()->login($user)) {
                        return $this->goHome();
                    }
                }
            }
        }
        return $this->render('signup', [
            'model' => $model,
        ]);
    }
    public function actionError(){
        return $this->render('error', [
            'code'=>'404',
        ]);
    }
    /**
     * Requests password reset.
     *
     * @return mixed
     */
    public function actionRequestPasswordReset()
    {
        $model = new PasswordResetRequestForm();
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if ($model->sendEmail()) {
                Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
                return $this->goHome();
            } else {
                Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
            }
        }
        return $this->render('requestPasswordResetToken', [
            'model' => $model,
        ]);
    }
    /**
     * Resets password.
     *
     * @param string $token
     * @return mixed
     * @throws BadRequestHttpException
     */
    public function actionResetPassword($token)
    {
        try {
            $model = new ResetPasswordForm($token);
        } catch (InvalidParamException $e) {
            throw new BadRequestHttpException($e->getMessage());
        }
        if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
            Yii::$app->session->setFlash('success', 'New password was saved.');
            return $this->goHome();
        }
        return $this->render('resetPassword', [
            'model' => $model,
        ]);
    }
    public function actionPriceparam ()
    {
        $category_alias = Yii::$app->request->get('category');
        $is_count = Yii::$app->request->get('count', false);
        if ( !($category = CategorySearch::findByAlias($category_alias)))
        {
            throw new HttpException(404, 'Данной страницы не существует!');
        }
        $products = $category->products;
        if ($is_count) {
            print (count($products));
            exit;
        }
        set_time_limit (0);
        header ("Content-Type: text/xml");
        print '';
        print "";
        print "" . date ("Y-m-d h:m") . "";
        print "www.linija-svitla.ua";
        print "";
        print "";
        print "";
        print "";
        print "" . $category->category_id . "";
        print "";
        print "" . $category->name . "";
        print "";
        print "";
        print "";
        /** @var Product $product */
        foreach ($products as $product) {
            /** @var ProductVariant $variant */
            foreach ($product->enabledVariants as $variant) {
                print "- ";
                print "" . htmlspecialchars($variant->product_variant_id) . "";
                print "" . htmlspecialchars($product->category->category_id) . "";
                print "" . $product->brand->name . "";
                print "" . htmlspecialchars($variant->sku) . "";
                print "" . htmlspecialchars(substr($category->name, 0, -2)) . " ";
                print "" . htmlspecialchars($product->name) . "  ";
                print "" . $variant->name . " ";
                print "" . htmlspecialchars($product->description) . "";
                print "http://www.linija-svitla.ua{$product->url}#{$variant->product_variant_id}";
                print "http://www.linija-svitla.ua{$variant->imageUrl}";
                print "" . $variant->price . "";
                print "" . $variant->price_old . "";
                print "";
                print "В наличии";
                print "";
                print "
";
            }
        }
        print "";
        print "";
    }
    public function actionPrice()
    {
        $category_alias = Yii::$app->request->get('category');
        $is_count = Yii::$app->request->get('count', false);
        if ( !($category = CategorySearch::findByAlias($category_alias)))
        {
            throw new HttpException(404, 'Данной страницы не существует!');
        }
        $products = $category->getProducts()->with(['filters','filters.group'])->joinWith('variant')->where(['product_variant.status'=>0])->all();
        if ($is_count) {
            print (count($products));
            exit;
        }
//var_dump($products);die();
        set_time_limit (0);
        header ("Content-Type: text/xml");
        print '';
        print "";
        print "" . date ("Y-m-d h:m") . "";
        print "www.linija-svitla.ua";
        print "";
        print "";
        print "";
        print "";
        print "" . $category->category_id . "";
        print "";
        print "" . $category->name . "";
        print "";
        print "";
        print "";
        /** @var Product $product */
        foreach ($products as $product)
        {
                print "- ";
                print "" . htmlspecialchars($product->variant->product_variant_id) . "";
                print "" . htmlspecialchars($product->category->category_id) . "";
                print "" . $product->brand->name . "";
                print "" . htmlspecialchars($product->variant->sku) . "";
                print "" . htmlspecialchars($product->name)." " .htmlspecialchars($product->variant->name). " ";
                print "" . htmlspecialchars($product->description) . "";
                print "http://www.linija-svitla.ua{$product->url}";
                print "http://www.linija-svitla.ua{$product->variant->imageUrl}";
                print "" . $product->variant->price . "";
                print "" . $product->variant->price_old . "";
                print "{$product->category->name}";
                $type = false;
                foreach( $product->filters as $filter){
                    if($filter->group->name == "Тип точечного освещение:"){
                        $type = true;
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Тип настенного освещения:"){
                        $type = true;
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Тип потолочного освещения:"){
                        $type = true;
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Тип уличного освещения:"){
                        $type = true;
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Тип лампочки:"){
                        $type = true;
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Назначение:"){
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Стиль:"){
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Количество лампочек:"){
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Тип источника света:"){
                        print "{$filter->name}";
                    }
                    if($filter->group->name == "Цоколь:"){
                        print "{$filter->name}";
                    }
                    //print "Припотолочная";
                }
                if(!$type){
                    print "{$product->category->name}";
                }
                print "";
                print "В наличии";
                print "";
                print "
";
        }
        print "";
        print "";
    }
}