Example #1
0
 function search()
 {
     $viewMode = $this->uri->segment(2, "") == "" ? "ma-tran" : $this->uri->segment(2);
     $orderBy = $this->uri->segment(3, "") == "" ? "moi-nhat" : $this->uri->segment(3);
     $page = $this->uri->segment(4, "") == "" ? "trang-1" : $this->uri->segment(4);
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $searchKey = $this->input->post('searchKey');
         $this->session->set_userdata('searchKey', $searchKey);
     }
     $searchKey = $this->session->userdata('searchkey');
     $limit = $viewMode == "ma-tran" ? 15 : 10;
     $offset = ($this->getPageNumber($page) - 1) * $limit;
     $product = new Product();
     if (trim($searchKey) != "") {
         $product->like('name', $searchKey);
     }
     $product->where('active', 1);
     $product->order_by($this->getOrderBy($orderBy), $this->getOrderDirection($orderBy));
     $product->get_paged_iterated();
     $dis['product'] = $product;
     $dis['pageUrl'] = "tim-kiem";
     $config['base_url'] = site_url($url . "/" . $viewMode . "/" . $orderBy . "/trang-");
     $config['total_rows'] = $product->paged->total_rows;
     $config['per_page'] = $limit;
     $config['use_page_numbers'] = TRUE;
     $config['uri_segment'] = 4;
     $config['num_links'] = 3;
     $config['full_tag_open'] = '<span class="pagin">';
     $config['full_tag_close'] = "</span>";
     $config['first_link'] = FALSE;
     $config['first_tag_open'] = '';
     $config['first_tag_close'] = '';
     $config['last_link'] = FALSE;
     $config['last_tag_open'] = '';
     $config['last_tag_close'] = '';
     $config['next_link'] = '<img src="' . base_url() . 'images/pagination_next.png" />';
     $config['next_tag_open'] = '';
     $config['next_tag_close'] = '';
     $config['prev_link'] = '<img src="' . base_url() . 'images/pagination_pre.png" /';
     $config['prev_tag_open'] = '';
     $config['prev_tag_close'] = '';
     $config['num_tag_open'] = '';
     $config['num_tag_close'] = '';
     $config['cur_tag_open'] = '<span class="active">';
     $config['cur_tag_close'] = '</span>';
     $this->pagination->initialize($config);
     if ($viewMode == 'ma-tran') {
         $dis['view'] = 'product/product_grid';
     } else {
         $dis['view'] = 'product/product_list';
     }
     $productSaleOff = new product();
     $productSaleOff->where('active', 1);
     $productSaleOff->where('isSale', 1);
     $productSaleOff->order_by('id', 'desc');
     $productSaleOff->get_iterated(15);
     $dis['productSaleOff'] = $productSaleOff;
     $dis['base_url'] = base_url();
     $this->viewfront($dis);
 }
Example #2
0
 function index_get()
 {
     $filters = $this->get("filter")["filters"];
     $page = $this->get('page') !== false ? $this->get('page') : 1;
     $limit = $this->get('limit') !== false ? $this->get('limit') : 50;
     $sort = $this->get("sort");
     $data["results"] = array();
     $data["count"] = 0;
     $obj = new Product(null, $this->entity);
     //Sort
     if (!empty($sort) && isset($sort)) {
         foreach ($sort as $value) {
             $obj->order_by($value["field"], $value["dir"]);
         }
     }
     //Filter
     if (!empty($filters) && isset($filters)) {
         $deleted = 0;
         foreach ($filters as $value) {
             if (!empty($value["operator"]) && isset($value["operator"])) {
                 if ($value["operator"] == "where_in") {
                     $obj->where_in($value["field"], $value["value"]);
                 } else {
                     if ($value["operator"] == "or_where_in") {
                         $obj->or_where_in($value["field"], $value["value"]);
                     } else {
                         if ($value["operator"] == "where_not_in") {
                             $obj->where_not_in($value["field"], $value["value"]);
                         } else {
                             if ($value["operator"] == "or_where_not_in") {
                                 $obj->or_where_not_in($value["field"], $value["value"]);
                             } else {
                                 if ($value["operator"] == "like") {
                                     $obj->like($value["field"], $value["value"]);
                                 } else {
                                     if ($value["operator"] == "or_like") {
                                         $obj->or_like($value["field"], $value["value"]);
                                     } else {
                                         if ($value["operator"] == "not_like") {
                                             $obj->not_like($value["field"], $value["value"]);
                                         } else {
                                             if ($value["operator"] == "or_not_like") {
                                                 $obj->or_not_like($value["field"], $value["value"]);
                                             } else {
                                                 if ($value["operator"] == "startswith") {
                                                     $obj->like($value["field"], $value["value"], "after");
                                                 } else {
                                                     if ($value["operator"] == "endswith") {
                                                         $obj->like($value["field"], $value["value"], "before");
                                                     } else {
                                                         if ($value["operator"] == "contains") {
                                                             $obj->like($value["field"], $value["value"], "both");
                                                         } else {
                                                             if ($value["operator"] == "or_where") {
                                                                 $obj->or_where($value["field"], $value["value"]);
                                                             } else {
                                                                 if ($value["operator"] == "by_vendor") {
                                                                     $obj->where_related("stock", $value["field"], $value["value"]);
                                                                 } else {
                                                                     if ($value["operator"] == "search") {
                                                                         $obj->like("sku", $value["value"], "after");
                                                                         $obj->or_like("name", $value["value"], "both");
                                                                         $obj->or_like("description", $value["value"], "both");
                                                                     } else {
                                                                         $obj->where($value["field"] . ' ' . $value["operator"], $value["value"]);
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 if ($value["field"] == "deleted") {
                     $deleted = $value["value"];
                 } else {
                     $obj->where($value["field"], $value["value"]);
                 }
             }
         }
         $obj->where("deleted", $deleted);
     }
     //Result
     $obj->get_paged_iterated($page, $limit);
     $data["count"] = $obj->paged->total_rows;
     if ($obj->result_count() > 0) {
         foreach ($obj as $value) {
             $priceList = array();
             foreach ($value->price_list->get() as $p) {
                 $priceList[] = array("id" => $p->id, "currency_id" => $p->currency_id, "product_id" => $p->product_id, "unit_id" => $p->unit_id, "price" => floatval($p->price), "unit_value" => floatval($p->unit_value), "locale" => $p->currency->get()->locale, "unit" => $p->unit->get()->name);
             }
             $cost = array();
             // foreach ($value->stock->order_by("issued_date", "desc")->get() as $c) {
             // 	$cost = array(
             // 		"id" 		=> $c->id,
             // 		"quantity" 	=> floatval($c->quantity),
             // 		"price" 	=> floatval($c->price),
             // 		"locale"	=> $c->currency->get()->locale,
             // 		"unit" 		=> $c->unit->get()->name
             // 	);
             // }
             $data["results"][] = array("id" => $value->id, "category_id" => $value->category_id, "unit_id" => $value->unit_id, "sku" => $value->sku, "name" => $value->name, "description" => $value->description, "on_hand" => floatval($value->on_hand), "order_point" => floatval($value->order_point), "favorite" => $value->favorite == 0 ? false : true, "image_url" => $value->image_url, "status" => $value->status == 0 ? false : true, "deleted" => $value->deleted, "unit" => $value->unit->get()->name, "cost" => $cost, "price_lists" => $priceList);
         }
     }
     //Response Data
     $this->response($data, 200);
 }