I have an input on cart page for affiliate's code. Users enter their codes and they can see affiliate's name top of the input if affiliate member is exist.
The question is; How can I make this input autocomplete? How can I add live search feature? It can be like admin/affiliate list page. I've tried to add this code which is in admin/controller/marketing/affiliate.php to catalog/controller/checkout/cart.php. However, I need your help. Thank you.
Opencart Version 2.1.0.2
Code: Select all
public function autocomplete() {
$affiliate_data = array();
if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_email'])) {
if (isset($this->request->get['filter_name'])) {
$filter_name = $this->request->get['filter_name'];
} else {
$filter_name = '';
}
if (isset($this->request->get['filter_email'])) {
$filter_email = $this->request->get['filter_email'];
} else {
$filter_email = '';
}
$this->load->model('marketing/affiliate');
$filter_data = array(
'filter_name' => $filter_name,
'filter_email' => $filter_email,
'start' => 0,
'limit' => 5
);
$results = $this->model_marketing_affiliate->getAffiliates($filter_data);
foreach ($results as $result) {
$affiliate_data[] = array(
'affiliate_id' => $result['affiliate_id'],
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
'email' => $result['email']
);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($affiliate_data));
}