Product::search PHP Method

    public function search()
    {
        $criteria = new CDbCriteria();
        $criteria->with = ['category', 'categories'];
        $criteria->compare('id', $this->id);
        $criteria->compare('t.type_id', $this->type_id);
        $criteria->compare('t.name', $this->name, true);
        $criteria->compare('t.price', $this->price);
        $criteria->compare('t.discount_price', $this->discount_price);
        $criteria->compare('t.sku', $this->sku, true);
        $criteria->compare('t.short_description', $this->short_description, true);
        $criteria->compare('t.description', $this->description, true);
        $criteria->compare('t.slug', $this->slug, true);
        $criteria->compare('t.data', $this->data, true);
        $criteria->compare('t.is_special', $this->is_special);
        $criteria->compare('t.status', $this->status);
        $criteria->compare('t.create_time', $this->create_time, true);
        $criteria->compare('t.update_time', $this->update_time, true);
        $criteria->compare('t.producer_id', $this->producer_id);
        $criteria->compare('t.purchase_price', $this->purchase_price);
        $criteria->compare('t.average_price', $this->average_price);
        $criteria->compare('t.recommended_price', $this->recommended_price);
        $criteria->compare('t.in_stock', $this->in_stock);
        $criteria->compare('t.quantity', $this->quantity);
        if ($this->category_id) {
            $categoryCriteria = new CDbCriteria();
            $categoryCriteria->compare('t.category_id', $this->category_id);
            $categoryCriteria->addCondition(sprintf('t.id IN (SELECT product_id FROM {{store_product_category}} WHERE category_id = :category_id)'), 'OR');
            $categoryCriteria->params = CMap::mergeArray($categoryCriteria->params, [':category_id' => $this->category_id]);
            $criteria->mergeWith($categoryCriteria);
        }
        return new CActiveDataProvider('Product', ['criteria' => $criteria, 'sort' => ['defaultOrder' => 't.update_time DESC, t.create_time DESC']]);
    }

Usage Example

 public function index()
 {
     // Check if user has sent a search query
     if ($query = Input::get('query', false)) {
         // Use the Elasticquent search method to search ElasticSearch
         $products = Product::search($query);
     } else {
         // Show all posts if no query is set
         $products = Product::all();
     }
     return View::make('products', compact('products'));
 }
All Usage Examples Of Product::search