// load required libraries
$this->load->library("pagination");
//initalise search data array
$uri_search_data = $this->uri->uri_to_assoc(3);
//set status
$search_data['products.status'] = Product::STATUS_ACTIVE;
// check url to see if any of the following segment pairs are set
if(isset($uri_search_data['category']))
{
$search_data['product_categories.category_name'] = urldecode($uri_search_data['category']);
}
if(isset($search_data['brand']))
{
$search_data['product_brands.brand_name'] = urldecode($uri_search_data['brand']);
}
if(isset($search_data['range']))
{
$search_data['product_ranges.range_name'] = urldecode($uri_search_data['range']);
}
//get number of items per page limit
$limit = 12;
// new empty product object
$product = new Product();
// get pagination config array
$config = array();
$config["base_url"] = base_url('our-products/browse/' . $this->uri->assoc_to_uri($uri_search_data));
$config["total_rows"] = $product->count_records();
$config["per_page"] = $limit;
$this->pagination->initialize($config);
// get offset from uri defaulting to 0 if not present
$offset = end($this->uri->segment_array()) ? end($this->uri->segment_array()) : 0;
// get all products
$products = $product->get_where($search_data, $order = NULL, $limit, $offset);
// assign data to view
$this->view_data['pagination_links'] = $this->pagination->create_links();
$this->view_data['products'] = $products;
// load default template
$this->parser->parse('website/products/list.tpl', $this->view_data);