public function actionProducts($slug = 'products')
 {
     $filterForm = new GadgetsFilterForm();
     $cat = Catalog::cat($slug);
     if (!$cat) {
         throw new NotFoundHttpException('Shop category not found.');
     }
     $filters = null;
     if ($filterForm->load(Yii::$app->request->get()) && $filterForm->validate()) {
         $filters = $filterForm->parse();
     }
     return $this->render('cat', ['cat' => $cat, 'items' => $cat->items(['pagination' => ['pageSize' => 2], 'filters' => $filters]), 'filterForm' => $filterForm]);
 }
 public function items($options = [])
 {
     if (!$this->_items) {
         $this->_items = [];
         $query = Item::find()->with('seo')->where(['category_id' => $this->id])->status(Item::STATUS_ON);
         if (!empty($options['where'])) {
             $query->andFilterWhere($options['where']);
         }
         if (!empty($options['orderBy'])) {
             $query->orderBy($options['orderBy']);
         } else {
             $query->sortDate();
         }
         if (!empty($options['filters'])) {
             $query = Catalog::applyFilters($options['filters'], $query);
         }
         $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []]);
         foreach ($this->_adp->models as $model) {
             $this->_items[] = new ItemObject($model);
         }
     }
     return $this->_items;
 }
Beispiel #3
0
 public function getCat()
 {
     return Catalog::cats()[$this->category_id];
 }