getListForCategory() public method

public getListForCategory ( StoreCategory $category, boolean $withChild = true, null $limit = null ) : CActiveDataProvider
$category StoreCategory
$withChild boolean
$limit null
return CActiveDataProvider
コード例 #1
0
 /**
  * @return bool
  * @throws CException
  */
 public function run()
 {
     $category = $this->categoryRepository->getByAlias($this->slug);
     if (null === $category) {
         return false;
     }
     $this->render($this->view, ['category' => $category, 'products' => $this->productRepository->getListForCategory($category, $this->limit)]);
 }
コード例 #2
0
ファイル: CategoryController.php プロジェクト: yupe/yupe
 /**
  * @param $path
  * @throws CHttpException
  */
 public function actionView($path)
 {
     $category = StoreCategory::model()->published()->findByPath($path);
     if (null === $category) {
         throw new CHttpException(404);
     }
     $data = Yii::app()->getRequest()->getQueryString() ? $this->productRepository->getByFilter($this->attributeFilter->getMainAttributesForSearchFromQuery(Yii::app()->getRequest(), [AttributeFilter::MAIN_SEARCH_PARAM_CATEGORY => [$category->id]]), $this->attributeFilter->getTypeAttributesForSearchFromQuery(Yii::app()->getRequest())) : $this->productRepository->getListForCategory($category);
     $this->render('view', ['dataProvider' => $data, 'category' => $category]);
 }
コード例 #3
0
 /**
  * Формирование списка категорий с товарами
  * @param  array $data массив категорий
  * @return boolean
  */
 private function createCatalogTree(array $data)
 {
     $this->activeLevel++;
     foreach ($data as $node) {
         //Добавление категории и декорирование ячейки
         $this->activeList->mergeCells('A' . $this->activeRow . ':D' . $this->activeRow)->setCellValue('A' . $this->activeRow, $this->addTabs($node['label']))->getStyle('A' . $this->activeRow . ':D' . $this->activeRow)->applyFromArray($this->getLevelStyle());
         $this->activeRow++;
         if (count($node['items'])) {
             //Если есть подкатегории используем рекурсию
             $this->createCatalogTree($node['items']);
         } else {
             //В противном случае тащим все товары категории
             $storeCategory = StoreCategory::model()->findByPk($node['id']);
             $dataProvider = $this->productRepository->getListForCategory($storeCategory);
             //И пишем их в таблицу
             foreach ($dataProvider->data as $product) {
                 $this->writeProductRow($product);
                 $this->activeRow++;
             }
         }
     }
     $this->activeLevel--;
     return true;
 }