function index() { $group_category = (int) @$_GET['cat_group_category']; $input = Input::Instance(); $category = new Category(); $db = Database::Instance(); $return = array(); $msgerror = null; $searchtxt = $input->get($this->inputtext); $liked = array("name_product" => $searchtxt, 'description_product' => $searchtxt); $likedstr = " (\n name_product LIKE '%{$searchtxt}%' OR description_product LIKE '%{$searchtxt}%' OR\n name_product_en LIKE '%{$searchtxt}%' OR description_product_en LIKE '%{$searchtxt}%'\n ) "; /* Count of Rows */ $result = $db->select("count(*) as total")->from("product")->where($likedstr); if ($group_category > 0) { $result = $result->from("product_has_category")->where(array('category_id_category' => $group_category))->where("product_id_product = id_product"); } $result = $result->get(); foreach ($result as $row) { $total = $row->total; } /* Class Pagination */ $this->pages = new Pagination(array('base_url' => "" . $this->__("search") . "/items/" . $this->__("page") . "/", 'uri_segment' => 'pagina', 'total_items' => $total, 'items_per_page' => $category->max_items_per_category, 'style' => $category->getstyle_pagination())); /* List of Products */ $result = $db->select("*")->from("product")->orderby(array("update_product" => "DESC"))->where("{$likedstr}")->limit($category->max_items_per_category)->offset($this->pages->sql_offset); /*Condition Category group*/ if ($group_category > 0) { $result = $result->from("product_has_category")->where(array('category_id_category' => $group_category))->where("product_id_product = id_product"); } /* Build The Result */ $result = $result->get(); foreach ($result as $row) { Basic::currency($row->price_product); if ($row->price_offer_product > 0) { Basic::currency($row->price_offer_product); $row->price_product = "<strike>" . $row->price_product . "</strike> {$this->separator_price} " . $row->price_offer_product; } $row->href_add_product = url::base() . $this->__("cart") . "/" . $this->__("add") . "/id/{$row->id_product}"; $row->href_detail_product = url::base() . $this->__("product") . "/" . $this->__("detail") . "/" . Basic::urlizar($row->name_product) . "/id/{$row->id_product}"; $return[] = $row; } /* Error Detecting */ if (count($return) < 1 or $searchtxt == null) { $return = array(); $msgerror = __("No se encontraron resultados", false); $this->pages = null; } // $this->content = View::factory("main/search_list_products") $this->title = __('Resultados de la búsqueda', false); $this->content = View::factory("main/list_products")->set('product', $return)->set('title', __('Resultados de la búsqueda', false))->set('msgerror', $msgerror)->set('pages', $this->pages)->render(); }