I'm new at programming and opencart, so I'm not very familiar with the site.
I'm creating a combobox of categories and subcategories on the addproduct page, where when selecting a category, another combo is generated with its subcategories.
For this I created a script by pulling the selected value and I will use it in the Controller to parameterize the array of the second combo (subcategories).
However, when I try to perform a $ _REQUEST ['product_category'] on the Controller, it says that this index is undefined.
I know there are some functions like "$ this-> load-> view -> ..." but I do not know how to use them in this case.
Could someone help me with the communication between view and controller and to make this request?
The codes are as follows:
VIEW
HTML:
Code: Select all
<form method="POST" action="addproduct.php">
<select name="product-category" id="product-category" size="10" class="form-control" onclick="myFunction()">
<option value="">Escolha a Categoria</option>
<?php foreach($product_categories as $product_category){ ?>
<option value="<?php echo $product_category['category_id'] ?>" ><?php echo $product_category['name'] ?></option>
<?php } ?>
</select>
<select name="product-subcategory1" id="product-subcategory1" size="10" class="form-control" onclick="myFunction1()">
<option value="">Escolha a Subcategoria</option>
<?php foreach($product_subcategories1 as $product_subcategory1){ ?>
<option value="<?php echo $product_subcategory1['category_id'] ?>"><?php echo $product_subcategory1['name'] ?></option>
<?php } ?>
</select>
</form>
Code: Select all
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.4.2");
</script>
<script type="text/javascript">
$(function(){
$('#product-category').change(function(){
if( $(this).val() ) {
$('#product-subcategory1').hide();
$.getJSON('addproduct.php?search=',{category_id: $(this).val(), ajax: 'true'}, function(j){
var options = '<option value="">Escolha Subcategoria</option>';
for (var i = 58; i < j.length; i++) {
options += '<option value="' + j[i].category_id + '">' + j[i].name + '</option>';
}
$('#product-subcategory1').html(options).show();
});
} else {
$('#product-subcategory1').html('<option value="">– Escolha Subcategoria –</option>');
}
});
});
</script>
CONTROLLER
PHP:
Code: Select all
@include_once('C:/xampp2/htdocs/alloeetestes/catalog/view/theme/journal2/template/account/customerpartner/addproduct.tpl');
$id_categoria = $_REQUEST['product_category'];
Thank you in advance for your help!