Example #1
0
 public function actionRenderpage($url)
 {
     $category = Category::findOne(['link' => $url]);
     if (empty($category)) {
         return $this->run('site/error');
     }
     $subcategories = Category::findAll(['parent' => $category->id]);
     $posts = Post::findAll(['category' => $category->id]);
     return $this->render('category', ['category' => $category, 'subcategories' => $subcategories, 'postsCount' => sizeof($posts), 'posts' => $posts, 'premiumPosts' => \common\models\Post::find()->where(['>', 'premium', date('d-m-Y H:i:s')])->andWhere(['category' => $category->id])->all()]);
 }
Example #2
0
 public function actionCreate()
 {
     $model = new Category();
     if (isset($_POST['sbm_create_category'])) {
         $model->load($_POST);
         //отправляем массив на парсинг
         var_dump($model);
         die;
         //$model->save();
     } else {
         $model = Category::findAll("where parent_id is NULL");
         //выбор коневых категорий
         $this->render('create', ['model' => $model]);
     }
 }
 public static function getProductByCategory($category_id, $limit = 6)
 {
     $category = new Category();
     $product = new Product();
     $categoriesData = $category->findAll(['parent_id' => $category_id]);
     $categoryIDs = [];
     if ($categoriesData) {
         foreach ($categoriesData as $categoryData) {
             $categoryIDs[] = $categoryData->id;
         }
         $products = $product->find()->where(['status' => 10, 'is_featured' => 10])->andWhere(['in', 'category_id', $categoryIDs])->limit($limit)->all();
     } else {
         $products = $product->find()->where(['status' => 10, 'is_front' => 10, 'category_id' => $category_id])->limit($limit)->all();
     }
     return $products;
 }
Example #4
0
 public function actionCatalog($id = null)
 {
     if ($id) {
         $categories = Category::findAll(['parent_id' => $id]);
         if ($categories === NULL) {
             throw new NotFoundHttpException("Категория {$id} не найдена");
         }
         $oneLevelCategory = Category::findOne(['id' => $id]);
         $this->getView()->title = "Mexanika 74 - Каталог техники: " . $oneLevelCategory->name . " - " . \common\components\Htmlhelper::getMetaList($categories);
         return $this->render('catalog', ['categories' => $categories, 'oneLevelCategory' => $oneLevelCategory]);
     } else {
         //получить разделы у "Каталог техники"
         $partions = Category::getPartions(Category::TECHNICS_ID);
         //получить все категории, входящие в разделы
         $oneLvl = Category::getFirstLevel(Category::TECHNICS_ID);
         $this->getView()->title = "Mexanika 74 - Каталог техники: " . \common\components\Htmlhelper::getMetaList($partions);
         return $this->render('catalog', ['categories' => $oneLvl, 'parents' => $partions]);
     }
 }
 public function run()
 {
     parent::run();
     // TODO: Change the autogenerated stub
     $category = new Category();
     $product = new Product();
     $parent_category = $category->findOne(['id' => $this->category_id]);
     $categoriesData = $category->findAll(['parent_id' => $this->category_id]);
     $category_slug = $parent_category->slug;
     $categoryIDs = [];
     if ($categoriesData) {
         foreach ($categoriesData as $categoryData) {
             $categoryIDs[] = $categoryData->id;
         }
         $products = $product->find()->where(['status' => 10, 'is_featured' => 10])->andWhere(['in', 'category_id', $categoryIDs])->limit($this->limit)->all();
     } else {
         $products = $product->find()->where(['status' => 10, 'is_front' => 10, 'category_id' => $this->category_id])->limit($this->limit)->all();
     }
     return $this->render('widget/front_product', ['nodes' => $products, 'category_slug' => $category_slug]);
 }
Example #6
0
 public function actionIndex()
 {
     $model = Category::findAll("where parent_id is NULL");
     //выбор коневых категорий
     $this->render('index', ['model' => $model]);
 }