Since Opencart is a customizable platform, let’s build a custom module. In this article I’m trying to fetch the list of registered customers into the front end, followed by the MVCL structure in Opencart. Several solutions for the issues I encountered while developing are included here. Let’s have a quick run through on it.. 😃
Purpose : To fetch the registered customer list
Steps >>
First make the controller (The path is as follows in my case)
Catalog > controller > account > registeredCustomers.php
Inside that, I just wanted to give a print line and check if it’s accessed in the front end. So, the following code is given.
<?php
class ControllerRegisteredCustomers extends Controller{
public function index(){
print_r("This is registered customer listing page");
}
}
I accessed the controller as given below, (need to access the controller by the file name)
http://localhost/custom-opencart/index.php?route=account/registeredCustomers
And following are the errors I encountered.


**2. Then in the language file, the attributes need to be shown to the page. I gave the following attributes.**
<?php
// Text
$_[‘title’] = ‘All Registered Customer’;
$_[‘meta_title’] = ‘All Registered Customers’;
$_[‘meta_description’] = ‘All Registered Customers’;
$_[‘meta_keyword’] = ‘All Registered Customers’;
$_[‘customers_text’] = ‘This is registered customers list page’;
**3. Then in the controller file, we can fetch the meta details given in the language file, and also the page header, footer designs as follows.**
<?php
class ControllerAccountRegisteredCustomers extends Controller{
public function index(){
$this->load->language(‘account/registeredCustomers’);
$this->document->setTitle($this->language->get(‘meta_title’));
$this->document->setDescription($this->language->get(‘meta_description’));
$this->document->setKeywords($this->language->get(‘meta_keyword’));
$data[‘column_left’] = $this->load->controller(‘common/column_left’);
$data[‘column_right’] = $this->load->controller(‘common/column_right’);
$data[‘content_top’] = $this->load->controller(‘common/content_top’);
$data[‘content_bottom’] = $this->load->controller(‘common/content_bottom’);
$data[‘footer’] = $this->load->controller(‘common/footer’);
$data[‘header’] = $this->load->controller(‘common/header’);
$this->response->setOutput($this->load->view(‘account/registeredCustomers’, $data));
}
}
**4. Thereafter the view file can be updated, so that we can check if the data fetched by the controller are shown on the page. (Include the following code inside the view file)**
{{ header }}
{{ column_left }}
{{ content_top}}
{{ content_bottom }}
{{ footer }}
5\. After that load the model into the controller, with which the database data can be retrieved. My model pat is,
**Catalog > model > account > registeredCustomerList.php**
$this->load->model(‘account/registeredCustomerList’);
This line loads the model. Here we’ll have to provide the exact path of the model where it is located.
$results = $this->model_account_registeredCustomerList->getRegisteredCustomers();
Then the method needs to be called inside the model.
6. Inside the model the data can be retrieved as required under the relevant method.
<?php
class ModelAccountRegisteredCustomerList extends Model {
public function getRegisteredCustomers() {
$query = $this->db->query(“SELECT * FROM `” . DB_PREFIX . “customer` ”);
return $query->rows;
}
}
Note :- Here also make sure to name the model class name with respect to the path.
**7. Thereafter, form an array with retrieved data and return it.**
<?php
class ControllerAccountRegisteredCustomers extends Controller
{
public function index(){
$this->load->language(‘account/registeredCustomers’);
$this->document->setTitle($this->language->get(‘meta_title’));
$this->document->setDescription($this->language->get(‘meta_description’));
$this->document->setKeywords($this->language->get(‘meta_keyword’));
$data[‘breadcrumbs’] = array();
$data[‘breadcrumbs’][] = array(
‘text’ => $this->language->get(‘text_home’),
‘href’ => $this->url->link(‘common/home’)
);
$data[‘breadcrumbs’][] = array(
‘text’ => $this->language->get(‘title’),
‘href’ => $this->url->link(‘account/registeredCustomers’)
);
$data[‘customers’] = array();
$this->load->model(‘account/registeredCustomerList’);
$results = $this->model_account_registeredCustomerList->getRegisteredCustomers();
foreach ($results as $key => $result) {
$data[‘customers’][] = $result;
}
$data[‘column_left’] = $this->load->controller(‘common/column_left’);
$data[‘column_right’] = $this->load->controller(‘common/column_right’);
$data[‘content_top’] = $this->load->controller(‘common/content_top’);
$data[‘content_bottom’] = $this->load->controller(‘common/content_bottom’);
$data[‘footer’] = $this->load->controller(‘common/footer’);
$data[‘header’] = $this->load->controller(‘common/header’);
$this->response->setOutput($this->load->view(‘account/registeredCustomers’, $data));
}
}
**8. Finally in the view file the data can be displayed as preferred.**
<ul class=“breadcrumb”>
{% for breadcrumb in breadcrumbs %}
<li><a href=“{{ breadcrumb.href }}”>{{ breadcrumb.text }}</a></li>
{% endfor %}
</ul>
<div class=“col-sm-12”>
<table class=“table table-striped”>
<thead>
<tr>
<th class=“text-center”>Name</th>
<th class=“text-center”>Email</th>
<th class=“text-center”>Telephone</th>
</tr>
</thead>
<tbody>
{% for customer in customers %}
<tr>
<td class=“text-center”>{{ customer.firstname }} {{ customer.lastname }}</td>
<td class=“text-center”>{{ customer.email }}</td>
<td class=“text-center”>{{ customer.telephone }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
Final output : 😄
