OpenCart 🇺🇦

Схема

public mixed autocomplete ( )

Аргументы

Аргумент Возможный тип Описание
У метода нет аргументов

Описание

Метод пока еще не документирован.

Исходный код

$json = array();

if (isset($this->request->get['filter_name'])) {
	$this->language->load('catalog/option');

	$this->load->model('catalog/option');

	$this->load->model('tool/image');

	$data = array(
		'filter_name' => $this->request->get['filter_name'],
		'start'       => 0,
		'limit'       => 20
	);

	$options = $this->model_catalog_option->getOptions($data);

	foreach ($options as $option) {
		$option_value_data = array();

		if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
			$option_values = $this->model_catalog_option->getOptionValues($option['option_id']);

			foreach ($option_values as $option_value) {
				if ($option_value['image'] && file_exists(DIR_IMAGE . $option_value['image'])) {
					$image = $this->model_tool_image->resize($option_value['image'], 50, 50);
				} else {
					$image = '';
				}

				$option_value_data[] = array(
					'option_value_id' => $option_value['option_value_id'],
					'name'            => html_entity_decode($option_value['name'], ENT_QUOTES, 'UTF-8'),
					'image'           => $image					
				);
			}

			$sort_order = array();

			foreach ($option_value_data as $key => $value) {
				$sort_order[$key] = $value['name'];
			}

			array_multisort($sort_order, SORT_ASC, $option_value_data);					
		}

		$type = '';

		if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
			$type = $this->language->get('text_choose');
		}

		if ($option['type'] == 'text' || $option['type'] == 'textarea') {
			$type = $this->language->get('text_input');
		}

		if ($option['type'] == 'file') {
			$type = $this->language->get('text_file');
		}

		if ($option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
			$type = $this->language->get('text_date');
		}

		$json[] = array(
			'option_id'    => $option['option_id'],
			'name'         => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
			'category'     => $type,
			'type'         => $option['type'],
			'option_value' => $option_value_data
		);
	}
}

$sort_order = array();

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

array_multisort($sort_order, SORT_ASC, $json);

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