I'm very new in MVC pattern using opencart 2.3.0.2. I try to create new field for username selection for add new product. The field what i want to do is drop down list using foreach. This is what i customize.
model/catalog/product/product.php file
<..some php code..>
public function getUser()
{
$query = $this->db->query("SELECT DISTINCT username, user_id FROM " . DB_PREFIX . "user");
return $query->row;
}
<..some php code..>
controller/catalog/controller/product.php file
<..some php code..>
public function add()
{
<..some php code..>
$this->load->model('catalog/product');
<..some php code..>
$this->getFormAdd();
}
protected function getFormAdd()
{
$theLists = $this->model_catalog_product->getUser();
$data['theLists'][] = array(
'username' => $theLists['username'],
'user_id' => $theLists['user_id']
);
<..some php code..>
$this->response->setOutput($this->load->view('catalog/product_formadd', $data));
}
view/catalog/product/product_formadd.tpl
<..some html code..>
<select style="background-color: FloralWhite;" name="filter_username" id="input-username" class="form-control">
<option value="*">Select Name</option>
<?php foreach ($username as $usernames) { ?>
<option value="<?php echo $user_ids; ?>" selected><?php echo $usernames; ?></option>
<?php } ?>
</select>
<..some html code..>
The website didnt show up the changes i done. Did i miss something out? Please help me! Fill free to ask me if miss understand. I will explain more. Thank in advance.