<?php 
class ControllerCatalogSizeProduct extends Controller {
    
        
	public function autocomplete() {
		$json = array();
		
		if (isset($this->request->get['filter_size'])) {
			$this->load->model('catalog/size_product');
			
			$data = array(
				'filter_size' => $this->request->get['filter_size'],
				'start'       => 0,
				'limit'       => 20
			);
			
			$results = $this->model_catalog_size_product->getSizes($data);
				
			foreach ($results as $result) {
				$json[] = array(
					'productsize_id' => $result['productsize_id'], 
					'description'     => strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))
				);
			}		
		}

		$sort_order = array();
	  
		foreach ($json as $key => $value) {
			$sort_order[$key] = $value['description'];
		}

		array_multisort($sort_order, SORT_ASC, $json);

		$this->response->setOutput(json_encode($json));
	}
}
