Create Custom Admin Page in OpenCart |
X

Congrats, You are Subscribed to Receive Updates.

Create Custom Admin Page in OpenCart


Opencart is one of  the popular eCommerce open source.  It works under the concept of  MVCL . Creating admin page requires a (MVC) control class, model class and view class, additionally one more class for language.

Create files like following structure inside your OpenCart admin folder like the following structure. Here you will see the final result.

admin/controller/kvc/first.php

admin/language/english/kvc/first.php

admin/model/kvc/first.php

admin/view/template/kvc/first.tpl

Here i named custom-folder name as “kvc” and custom-file-name as “kvc.php” . here are the few steps to get your admin page.

create-custom-admin-page-in-opencart

1) Create a new file in admin/controller/kvc/first.php

Your file name and controller name should be the same in desc order:

first.php

<?php

class ControllerKvcFirst extends Controller{ 
    public function index(){
                // VARS
        $template="kvc/first.tpl"; 			// .tpl location and file
        $this->load->model('kvc/first');	// model class file
		$this->load->language('kvc/first'); //language class file
        $this->template = ''.$template.'';
        $this->children = array(
            'common/header',
            'common/footer'
        );      
        $this->response->setOutput($this->render());
    }
}
?>

2) Create a new file in admin/model/kvc/first.php

<?php
class ModelKvcFirst extends Model {
    public function firstfunction() {

		//This is for just a demo purpose. 
        $sql = "SELECT x FROM `" . DB_PREFIX . "y`)"; 
        $implode = array();
        $query = $this->db->query($sql);
        return $query->row['total'];    
    }       
}
?>

3) Create a new file in admin/view/template/kvc/first.tpl

first.tpl

<?php echo $header; ?>
<div id="content">
<h1>My First Admin Page</h1>
<?php
echo 'I can also create a custom admin page.!'; 
?>
</div> 
<?php echo $footer; ?>

4)  Create a new file in admin/language/english/kvc/first.php

<?php
// Heading
$_['heading_title']       = 'My First AdminPage';

// Text
$_['text_module']         = 'Modules';
$_['text_success']        = 'Success: You have modified module account!';
$_['text_content_top']    = 'Content Top';
$_['text_content_bottom'] = 'Content Bottom';
$_['text_column_left']    = 'Column Left';
$_['text_column_right']   = 'Column Right';

// Entry
$_['entry_layout']        = 'Layout:';
$_['entry_position']      = 'Position:';
$_['entry_status']        = 'Status:';
$_['entry_sort_order']    = 'Sort Order:';

// Error
$_['error_permission']    = 'Warning: You do not have permission to modify module account!';
?>

5) You then need to enable the plugin to avoid permission denied errors:

Opencart > Admin > Users > User Groups > Admin > Edit
Select and Enable the Modifiy and Access Permission for kvc/first

usr_grp
Thats it. Now you can access your custom page by the following url

www.yoursite.com/opencart/admin/index.php?route=kvc/first&token= here-your-token-key.

oc_admin_page

 

If you want to set the directory permission programmatically Read here. 

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

34 comments

  1. commenter

    Dear Varadharajv,

    Please, help me, I doit everything like you posted in this link:
    https://kvcodes.com/2013/10/create-custom-admin-page-open-cart/#respond

    But after when I tried to acces the new page, allways the system is log me out, I got this message “Invalid token session. Please login again.”

    I using opencart 1.5.6

    Thanks in advance your answer,

    Regards,

    Ben

    • commenter

      hi ben ,
      you are missed to do the 5th step. you have to set user access
      permission , otherwise it will through a security exception and
      ask you to login again.

      • commenter

        Thank You for the prompt help, but in time I found what was missed, this I had to add in

        admin/controller/common/header.php

        $this->data[‘first’] = $this->url->link(‘kvc/first’, ‘token=’ . $this->session->data[‘token’], ‘SSL’);
        Link to page admin/view/template/common/header.tpl

        <a href="”>First Page

        could you please, update this in your tutorial.

        Thanks again.

        regards,
        Ben

  2. commenter

    error Notice: Error: Could not load language kvc/first! in D:\xampp\htdocs\opencart\system\library\language.php on line 39

    • commenter

      You are missed to create kvc/first.php language file. Kindly check ur language directory , if its available there reply me with your code. I will help you.

      • commenter

        Notice: Error: Could not load language forms/jumphire! in /home3/leadnex/public_html/ewebsoul.com/projects/php/kangoo/system/library/language.php on line 39

        kvc/first.php file is also available

        same problem i face plz help.

  3. commenter

    Create Custom Admin Page – OpenCart its for nice too!

  4. commenter

    Dear Varadharajv, this is a very nice and helpful article.

  5. commenter

    I have created custom page and it worked in admin
    but when i click on it it logs out and asks me to log in

    Please update me solution as soon as possbile.

  6. commenter

    Hi, The function is working nice and fine. I got one more question, thats is how to link the url in the admin page in the menu? Do you have tutorial for this? Please assist. Thanks.

  7. commenter

    Hi, The function is working . i just done all the steps including user group permissions also, but still there showing Permission Denied!

    • commenter

      try Ben’s code to get access through programmatically.

       
      $this->data['first'] = $this->url->link(‘kvc/first’, ‘token=’ . $this->session->data['token'], ‘SSL’);
      
  8. commenter

    In the tutorial, you say:
    Create a new file in admin/language/kvc/first.tpl
    But it’s first.php right? instead of first.tpl

  9. commenter

    Another point:
    The kvc folder must be in the english folder otherwise I have an error.
    (admin/language/english/kvc/first.php)

  10. commenter
    Pacific Polythene

    4) Create a new file in admin/language/english/kvc/first.tpl

    should be

    4) Create a new file in admin/language/english/kvc/first.php

  11. commenter

    I followed all the above steps but after I completed the last step where I enabled the plugin via Opencart > Admin > Users > User Groups > Admin > Edit, then I tried my custom page and I received “The website cannot display the page HTTP 500” error.

    Where could be the problem?

  12. commenter

    hi

    I am using the same code you mention in the page but it shows me Fatal error: Class ‘Controllercustomapp’ not found in C:\wamp\www\opencart\upload\system\engine\action.php on line 62. or blank white page. can you please tell where i am going wrong?

    • commenter

      I wrote the article for the opencart 1. 5 versions. But now a days it’s 2 above. So there might be some upgrades and easier functions may came now.

      And also the functions points the error in the system files. So there might be alternative way is discovered with core of opencart

  13. commenter

    How can I link custom inner pages in opencart admin

  14. commenter

    Hello and thank you for this helpful tutorial,

    I’ve one question in addition,

    Although new module after setting a permissions works, I’m getting no results with db query from your example and selected table ‘order’

    ‘class ModelKvcFirst extends Model {
    public function firstfunction() {

    //This is for just a demo purpose.
    $sql = “SELECT x FROM `” . DB_PREFIX . “order`)”;
    $implode = array();
    $query = $this->db->query($sql);
    return $query->row[‘total’];
    }
    }’

    I’ve another example

    ‘class ModelKvcFirst extends Model {
    public function firstfunction() {

    $query = “SELECT order_id, customer_id, firstname, lastname, email FROM `order`”;
    $value = mysql_query($query) or die(‘Query failed: ‘ . mysql_error());

    echo “\n”;
    while ($line = mysql_fetch_array($value, MYSQL_ASSOC)) {
    echo “\t\n”;
    foreach ($line as $col_value) {
    echo “\t\t$col_value\n”;
    }
    echo “\t\n”;
    }
    echo “\n”;

    mysql_free_result($query);

    }
    }’

    But no db results – I’ve also tried echoing values of total, row and query in template but queries are not outputting,

    Please reply with your expertise

  15. commenter

    Hello My friend
    thank you for this helpful tutorial
    I do this example and do not have any error but my last result is a blank page
    why ?

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar