<?php 
class ControllerCatalogColorProduct extends Controller {
    
        
	public function autocomplete() {
		$json = array();
		
		if (isset($this->request->get['filter_color'])) {
			$this->load->model('catalog/color_product');
			
			$data = array(
				'filter_color' => $this->request->get['filter_color'],
				'start'       => 0,
				'limit'       => 20
			);
			
			$results = $this->model_catalog_color_product->getColors($data);
				
			foreach ($results as $result) {
				$json[] = array(
					'productcolor_id' => $result['productcolor_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));
	}
        
}
