Search code examples
opencartopencart2.xopencart2.3ocmodopencart-events

Add submenu in OpenCart by events in admin area


I want to add a sub menu in OpenCart, under catalog menu in admin area. in past we used ocmod or vqmod for do this, an example by ocmod is here:

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <code>submenu5</code>
    <name>submenu5</name>
    <version>2.3</version>
    <author>codertj</author>
    <link>codertj.com</link>

    <!-- edit header controller -->
    <file path="admin/controller/common/column_left.php">
    <!-- create link to your page -->   
        <operation error="log">
            <search><![CDATA[if ($this->user->hasPermission('access', 'catalog/product')) {]]></search>
            <add  position="before"><![CDATA[
                if ($this->user->hasPermission('access', 'catalog/product')) {
                    $catalog[] = array(
                        'name'     => $this->language->get('text_hello_world'),
                        'href'     => $this->url->link('report/helloworld', 'token=' . $this->session->data['token'], true),
                        'children' => array()   
                    );
                }
            ]]></add>
        </operation>
    </file>

    <!-- edit header template -->
    <file path="admin/language/en-gb/common/column_left.php">
        <operation error="log">
            <search><![CDATA[$_['text_product']]]></search>
            <add  position="before"><![CDATA[
               $_['text_hello_world']             = 'Hello World';
            ]]></add>
        </operation>
    </file>

</modification> 

Now opencart use of Events system, but I can't find solution for convert this ocmod to event!


Solution

  • You can do that in this way, We assume that you have recorded the event in the database, if you did not do this, you can create it quickly with the following query:

    INSERT INTO `oc_event` (`code`, `trigger`, `action`, `status`) VALUES ('mymodule', 'admin/view/common/column_left/before', 'extension/module/mymodule/addSubmenu', 1)
    

    admin\controller\extension\module\mymodule.php

    <?php
    class ControllerExtensionModuleMymodule extends Controller {
        public function addSubmenu(&$route = false, &$data = false, &$output = false){
            $my_language = $this->load->language('extension/module/mymodule');
            $data['menus'][1]['children'][] = array(
                'name'     => $my_language['text_hello_world'],
                'href'     => $this->url->link('report/helloworld', 'token=' . $this->session->data['token'], true),
                'children' => array()
            );
        }
    }
    

    admin\language\en-gb\extension\module\mymodule.php

    <?php
    $_['text_hello_world']      = 'Hello World!';
    

    I tested this with OpenCart 2.3