Я знаю)
Пример из модуля
<link rel="stylesheet" href="view/javascript/jquery/select2/select2.min.css">
<link rel="stylesheet" href="view/javascript/jquery/select2/select2-bootstrap.min.css">
<script src="view/javascript/jquery/select2/select2.full.min.js"></script>
<select name="products[]" id="products_search" class="products" multiple="multiple">
<?php if ($settings['products_parsed']): ?>
<?php foreach ($settings['products_parsed'] as $product): ?>
<option value="<?php echo $product['id']; ?>" selected><?php echo $product['name']; ?></option>
<?php endforeach ?>
<?php endif ?>
</select>
<script>
$('#products_search').select2({
dropdownParent: $('#el_settings'),
theme: "bootstrap",
placeholder: "<?php echo $text_form_autocomplete ?>",
multiple: true,
closeOnSelect: false,
ajax: {
url: '<?php echo $product_autocomplete ?>',
dataType: 'json'
}
});
</script>
public function product_autocomplete()
{
$json = array();
if (isset($this->request->get['term'])) {
$this->load->model('catalog/product');
$this->load->model('catalog/option');
if (isset($this->request->get['limit'])) {
$limit = $this->request->get['limit'];
} else {
$limit = 5;
}
$filter_data = array(
'filter_name' => $this->request->get['term'],
'filter_model' => '',
'start' => 0,
'limit' => $limit
);
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
$json['results'][] = array(
'id' => $result['product_id'],
'text' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}