public function getListForCategory(StoreCategory $category, $withChild = true, $limit = null)
{
$categories = [];
if (true === $withChild) {
$categories = $category->getChildsArray();
}
$categories[] = $category->id;
$criteria = new CDbCriteria(['scopes' => ['published']]);
$builder = new CDbCommandBuilder(Yii::app()->getDb()->getSchema());
$criteria->addInCondition('t.category_id', array_unique($categories));
$criteria->addCondition(sprintf('t.id IN (SELECT product_id FROM {{store_product_category}} WHERE %s)', $builder->createInCondition('{{store_product_category}}', 'category_id', $categories)), 'OR');
$pagination = ['pageSize' => (int) Yii::app()->getModule('store')->itemsPerPage, 'pageVar' => 'page'];
if ($limit) {
$pagination = false;
$criteria->limit = (int) $limit;
}
return new CActiveDataProvider(Product::model(), ['criteria' => $criteria, 'pagination' => $pagination, 'sort' => ['sortVar' => 'sort', 'defaultOrder' => 't.position']]);
}