/** * Search products * @param $data ShopCategory|string * @param string $view */ public function doSearch($data, $view) { $this->query = new ShopProduct(null); $this->query->attachBehaviors($this->query->behaviors()); $this->query->applyAttributes($this->activeAttributes)->active(); if ($data instanceof ShopCategory) { $this->query->applyCategories($this->model); } else { $cr = new CDbCriteria(); $cr->with = array('translate' => array('together' => true)); $cr->addSearchCondition('translate.name', $data); $this->query->getDbCriteria()->mergeWith($cr); } // Filter by manufacturer if (Yii::app()->request->getQuery('manufacturer')) { $manufacturers = explode(',', Yii::app()->request->getParam('manufacturer', '')); // ; $this->query->applyManufacturers($manufacturers); } // Create clone of the current query to use later to get min and max prices. $this->currentQuery = clone $this->query->getDbCriteria(); // Filter products by price range if we have min_price or max_price in request $this->applyPricesFilter(); $per_page = $this->allowedPageLimit[0]; if (isset($_GET['per_page']) && in_array((int) $_GET['per_page'], $this->allowedPageLimit)) { $per_page = (int) $_GET['per_page']; } $this->provider = new ActiveDataProvider($this->query, array('id' => false, 'pagination' => array('pageSize' => $per_page))); $this->provider->sort = ShopProduct::getCSort(); if ($view != 'search') { $this->pageKeywords = $this->model->keywords(); $this->pageDescription = $this->model->description(); $this->pageTitle = $this->model->title(); // Create breadcrumbs $ancestors = $this->model->cache($this->cacheTime)->excludeRoot()->ancestors()->findAll(); // $this->breadcrumbs = array(Yii::t('ShopModule.default', 'BC_SHOP') => '/shop'); foreach ($ancestors as $c) { $this->breadcrumbs[$c->name] = $c->getViewUrl(); } $this->breadcrumbs[] = $this->model->name; } if (isset($_GET['view'])) { if ($_GET['view'] == 'list') { $itemView = '_view_list'; } elseif ($_GET['view'] == 'table') { $itemView = '_view_table'; } else { $itemView = '_view_grid'; } } else { $itemView = '_view_grid'; } $this->render($view, array('provider' => $this->provider, 'itemView' => $itemView)); }
/** * Display products by manufacturer * * @param $seo_alias * @throws CHttpException */ public function actionIndex($seo_alias) { $this->model = ShopManufacturer::model()->findByAttributes(array('seo_alias' => $seo_alias)); if (!$this->model) { throw new CHttpException(404, Yii::t('ShopModule.admin', 'NO_FOUND_BRAND')); } $this->pageTitle = $this->model->seo_title ? $this->model->seo_title : $this->model->name; $this->pageKeywords = $this->model->seo_keywords; $this->pageDescription = $this->model->seo_description; $query = new ShopProduct(null); $query->attachBehaviors($query->behaviors()); $query->active(); $query->applyManufacturers($this->model->id); $provider = new ActiveDataProvider($query, array('id' => false, 'pagination' => array('pageSize' => $this->allowedPageLimit[0]))); $this->render('index', array('provider' => $provider)); }
/** * @return array of category manufacturers */ public function getCategoryManufacturers() { $cr = new CDbCriteria(); $cr->select = 't.manufacturer_id, t.id'; $cr->group = 't.manufacturer_id'; $cr->addCondition('t.manufacturer_id IS NOT NULL'); //@todo: Fix manufacturer translation $mdl = $this->model; $dependency = new CDbCacheDependency('SELECT MAX(date_update) FROM {{shop_product}}'); //$dependency = new CChainedCacheDependency(); $manufacturers = ShopProduct::model()->cache($this->controller->cacheTime, $dependency)->active()->applyCategories($mdl, null)->with(array('manufacturer' => array('with' => array('productsCount' => array('scopes' => array('active', 'applyCategories' => array($mdl, null), 'applyAttributes' => array($this->getOwner()->activeAttributes), 'applyMinPrice' => array($this->convertCurrency(Yii::app()->request->getQuery('min_price'))), 'applyMaxPrice' => array($this->convertCurrency(Yii::app()->request->getQuery('max_price')))))))))->findAll($cr); $data = array('title' => Yii::t('default', 'Производитель'), 'selectMany' => true, 'filters' => array()); if ($manufacturers) { foreach ($manufacturers as $m) { $m = $m->manufacturer; if ($m) { $model = new ShopProduct(null); $model->attachBehaviors($model->behaviors()); $model->active()->cache($this->controller->cacheTime, $dependency)->applyCategories($this->model)->applyMinPrice($this->convertCurrency(Yii::app()->request->getQuery('min_price')))->applyMaxPrice($this->convertCurrency(Yii::app()->request->getQuery('max_price')))->applyAttributes($this->getOwner()->activeAttributes)->applyManufacturers($m->id); $data['filters'][] = array('title' => $m->name, 'count' => $model->count(), 'queryKey' => 'manufacturer', 'queryParam' => $m->id); } } } return $data; }