예제 #1
0
파일: Search.php 프로젝트: buzkall/GoCart3
 public function index($code = false, $page = 0)
 {
     $pagination_base_url = site_url('search/' . $code);
     //how many products do we want to display per page?
     //this is configurable from the admin settings page.
     $per_page = config_item('products_per_page');
     \CI::load()->model('Search');
     //check to see if we have a search term
     if (!$code) {
         //if the term is in post, save it to the db and give me a reference
         $term = \CI::input()->post('term', true);
         if (empty($term)) {
             //if there is still no search term throw an error
             $data['error'] = lang('search_error');
             $this->view('search_error', $data);
             return;
         } else {
             $code = \CI::Search()->recordTerm($term);
             // no code? redirect so we can have the code in place for the sorting.
             // I know this isn't the best way...
             redirect('search/' . $code . '/' . $page);
         }
     } else {
         //if we have the md5 string, get the term
         $term = \CI::Search()->getTerm($code);
     }
     //fix for the category view page.
     $data['base_url'] = [];
     $sortArray = array('name/asc' => array('by' => 'name', 'sort' => 'ASC'), 'name/desc' => array('by' => 'name', 'sort' => 'DESC'), 'price/asc' => array('by' => 'price', 'sort' => 'ASC'), 'price/desc' => array('by' => 'price', 'sort' => 'DESC'));
     $sortBy = array('by' => false, 'sort' => false);
     if (isset($_GET['by'])) {
         if (isset($sortArray[$_GET['by']])) {
             $sortBy = $sortArray[$_GET['by']];
         }
     }
     if (empty($term)) {
         //if there is still no search term throw an error
         $this->view('search_error', $data);
         return;
     } else {
         $result = \CI::Products()->search_products($term, $per_page, $page, $sortBy['by'], $sortBy['sort']);
         $config['total_rows'] = $result['count'];
         \CI::load()->library('pagination');
         $config['base_url'] = $pagination_base_url;
         $config['uri_segment'] = 3;
         $config['per_page'] = $per_page;
         $config['num_links'] = 3;
         $config['total_rows'] = $result['count'];
         \CI::pagination()->initialize($config);
         $data['products'] = $result['products'];
         $data['category'] = (object) ['name' => str_replace('{term}', $term, lang('search_title'))];
         $this->view('categories/category', $data);
     }
 }
예제 #2
0
 public function index($rows = 100, $order_by = "name", $sort_order = "ASC", $code = 0, $page = 0)
 {
     $data['groups'] = \CI::Customers()->get_groups();
     $data['page_title'] = lang('products');
     $data['code'] = $code;
     $term = false;
     $category_id = false;
     //get the category list for the drop menu
     $data['categories'] = \CI::Categories()->getCategoryOptionsMenu();
     $post = \CI::input()->post(null, false);
     \CI::load()->model('Search');
     if ($post) {
         $term = json_encode($post);
         $code = \CI::Search()->recordTerm($term);
         $data['code'] = $code;
     } elseif ($code) {
         $term = \CI::Search()->getTerm($code);
     }
     //store the search term
     $data['term'] = $term;
     $data['order_by'] = $order_by;
     $data['sort_order'] = $sort_order;
     $data['rows'] = $rows;
     $data['page'] = $page;
     $data['products'] = \CI::Products()->products(array('term' => $term, 'order_by' => $order_by, 'sort_order' => $sort_order, 'rows' => $rows, 'page' => $page));
     //total number of products
     $data['total'] = \CI::Products()->products(array('term' => $term, 'order_by' => $order_by, 'sort_order' => $sort_order), true);
     \CI::load()->library('pagination');
     $config['base_url'] = site_url('admin/products/' . $rows . '/' . $order_by . '/' . $sort_order . '/' . $code . '/');
     $config['total_rows'] = $data['total'];
     $config['per_page'] = $rows;
     $config['uri_segment'] = 7;
     $config['first_link'] = 'First';
     $config['first_tag_open'] = '<li>';
     $config['first_tag_close'] = '</li>';
     $config['last_link'] = 'Last';
     $config['last_tag_open'] = '<li>';
     $config['last_tag_close'] = '</li>';
     $config['full_tag_open'] = '<nav><ul class="pagination">';
     $config['full_tag_close'] = '</ul></nav>';
     $config['cur_tag_open'] = '<li class="active"><a href="#">';
     $config['cur_tag_close'] = '</a></li>';
     $config['num_tag_open'] = '<li>';
     $config['num_tag_close'] = '</li>';
     $config['prev_link'] = '&laquo;';
     $config['prev_tag_open'] = '<li>';
     $config['prev_tag_close'] = '</li>';
     $config['next_link'] = '&raquo;';
     $config['next_tag_open'] = '<li>';
     $config['next_tag_close'] = '</li>';
     \CI::pagination()->initialize($config);
     $this->view('products', $data);
 }
예제 #3
0
 public function index($sort_by = 'order_number', $sort_order = 'desc', $code = 0, $page = 0, $rows = 100)
 {
     //if they submitted an export form do the export
     if (\CI::input()->post('submit') == 'export') {
         \CI::load()->model('Customers');
         \CI::load()->helper('download_helper');
         $post = \CI::input()->post(null, false);
         $term = (object) $post;
         $data['orders'] = \CI::Orders()->getOrders($term);
         foreach ($data['orders'] as &$o) {
             $o->items = \CI::Orders()->getItems($o->id);
         }
         force_download('orders.json', json_encode($data));
         return;
     }
     \CI::load()->helper('form');
     \CI::load()->helper('date');
     $data['message'] = \CI::session()->flashdata('message');
     $data['page_title'] = lang('orders');
     $data['code'] = $code;
     $term = false;
     $post = \CI::input()->post(null, false);
     if ($post) {
         //if the term is in post, save it to the db and give me a reference
         $term = json_encode($post);
         $code = \CI::Search()->recordTerm($term);
         $data['code'] = $code;
         //reset the term to an object for use
         $term = (object) $post;
     } elseif ($code) {
         $term = \CI::Search()->getTerm($code);
         $term = json_decode($term);
     }
     $data['term'] = $term;
     $data['orders'] = \CI::Orders()->getOrders($term, $sort_by, $sort_order, $rows, $page);
     $data['total'] = \CI::Orders()->getOrderCount($term);
     \CI::load()->library('pagination');
     $config['base_url'] = site_url('admin/orders/index/' . $sort_by . '/' . $sort_order . '/' . $code . '/');
     $config['total_rows'] = $data['total'];
     $config['per_page'] = $rows;
     $config['uri_segment'] = 7;
     $config['first_link'] = 'First';
     $config['first_tag_open'] = '<li>';
     $config['first_tag_close'] = '</li>';
     $config['last_link'] = 'Last';
     $config['last_tag_open'] = '<li>';
     $config['last_tag_close'] = '</li>';
     $config['full_tag_open'] = '<nav><ul class="pagination">';
     $config['full_tag_close'] = '</ul></nav>';
     $config['cur_tag_open'] = '<li class="active"><a href="#">';
     $config['cur_tag_close'] = '</a></li>';
     $config['num_tag_open'] = '<li>';
     $config['num_tag_close'] = '</li>';
     $config['prev_link'] = '&laquo;';
     $config['prev_tag_open'] = '<li>';
     $config['prev_tag_close'] = '</li>';
     $config['next_link'] = '&raquo;';
     $config['next_tag_open'] = '<li>';
     $config['next_tag_close'] = '</li>';
     \CI::pagination()->initialize($config);
     $data['sort_by'] = $sort_by;
     $data['sort_order'] = $sort_order;
     $this->view('orders', $data);
 }