/**
  * Retrieves a list of models based on the current search/filter conditions.
  * @param $params
  * @param $additionalCriteria
  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  */
 public function search($params = array(), $additionalCriteria = null)
 {
     $criteria = new CDbCriteria();
     $criteria->with = array('categorization', 'translate', 'type');
     if ($additionalCriteria !== null) {
         $criteria->mergeWith($additionalCriteria);
     }
     if ($this->manufacturer_id) {
         $manufacturerCr = new CDbCriteria();
         $manufacturerCr->with = array('manufacturer');
         $criteria->mergeWith($manufacturerCr);
     }
     $ids = $this->id;
     // Adds ability to accepts id as "1,2,3" string
     if (false !== strpos($ids, ',')) {
         $ids = explode(',', $this->id);
         $ids = array_map('trim', $ids);
     }
     $criteria->compare('t.id', $ids);
     $criteria->compare('translate.name', $this->name, true);
     $criteria->compare('t.url', $this->url, true);
     $criteria->compare('t.price', $this->price);
     $criteria->compare('t.is_active', $this->is_active);
     $criteria->compare('translate.short_description', $this->short_description, true);
     $criteria->compare('translate.full_description', $this->full_description, true);
     $criteria->compare('t.sku', $this->sku, true);
     $criteria->compare('t.created', $this->created, true);
     $criteria->compare('t.updated', $this->updated, true);
     $criteria->compare('type_id', $this->type_id);
     $criteria->compare('manufacturer_id', $this->manufacturer_id);
     if (isset($params['category']) && $params['category']) {
         $criteria->with = array('categorization' => array('together' => true));
         $criteria->compare('categorization.category', $params['category']);
     }
     // Id of product to exclude from search
     if ($this->exclude) {
         $criteria->compare('t.id !', array(':id' => $this->exclude));
     }
     return new CActiveDataProvider($this, array('criteria' => $criteria, 'sort' => StoreProduct::getCSort()));
 }
 /**
  * Search products
  * @param $data StoreCategory|string
  * @param string $view
  */
 public function doSearch($data, $view)
 {
     $this->query = new StoreProduct(null);
     $this->query->attachBehaviors($this->query->behaviors());
     $this->query->applyAttributes($this->activeAttributes)->active();
     if ($data instanceof StoreCategory) {
         $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 CActiveDataProvider($this->query, array('id' => false, 'pagination' => array('pageSize' => $per_page)));
     $this->provider->sort = StoreProduct::getCSort();
     $this->render($view, array('provider' => $this->provider, 'itemView' => isset($_GET['view']) && $_GET['view'] === 'wide' ? '_product_wide' : '_product'));
 }