I am a newbie in Opencart. I'm trying to develop a custom module that gets the list of categories and when i select one of them, it displays the list of products for this category. I'm trying to do it via AJAX get request but i have some problems with id.
AJAX function in .tpl file
Code: Select all
<script>
$('#category').on('change', function() { //#category is an id for <select> list with categories
$.ajax({
method: 'GET',
url: 'index.php?route=module/my_module&category_id='+this.value, //here i set up a url to controller and parameter for get query
}).done(function(data, Status){
});
});
</script>
Code: Select all
$this->load->model('catalog/product');
$category_id = $this->request->get['category_id']; //here i try to catch the get data but it can't
$this->data['product'] = $this->model_catalog_product->getProductsByCategoryId($category_id);
$this->response->setOutput();
Thank you in advance.