Post by Dutch Pride Code » Sat Jul 31, 2021 5:12 am

Hi everybody,

Please bear with me as I am trying to learn development and it's not easy. Especially for OpenCart without any decent documentation available. As I am trying to develop a very plain and simple (single instance) admin extension as one of my first attempts, I stumbled upon this problem where the extension just won't get enabled. After saving it the status just restores back to 'disabled'. Does anybody know what I did wrong here? Any help is much appreciated.

My OC version is 3.0.3.7, installed on a local server and the file below is the controller I've created.

Code: Select all

<?php
class ControllerExtensionModuleTkmanager extends Controller {
	private $error = array();

	public function index() {
		$this->load->language('extension/module/tkmanager');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('setting/module');

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->load->model('setting/setting');
            $this->model_setting_setting->editSetting('extension_module_tkmanager', $this->request->post);
            $this->session->data['success'] = $this->language->get('text_success');
            $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));
        }

		if (isset($this->error['warning'])) {
			$data['error_warning'] = $this->error['warning'];
		} else {
			$data['error_warning'] = '';
		}

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_home'),
			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_extension'),
			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)
		);

		if (!isset($this->request->get['module_id'])) {
			$data['breadcrumbs'][] = array(
				'text' => $this->language->get('heading_title'),
				'href' => $this->url->link('extension/module/tkmanager', 'user_token=' . $this->session->data['user_token'], true)
			);
		} else {
			$data['breadcrumbs'][] = array(
				'text' => $this->language->get('heading_title'),
				'href' => $this->url->link('extension/module/tkmanager', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true)
			);
		}

		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);

		if (isset($this->request->post['module_tkmanager_status'])) {
                        $data['module_tkmanager_status'] = $this->request->post['module_tkmanager_status'];
                } else {
                        $data['module_tkmanager_status'] = $this->config->get('module_tkmanager_status');
                }

		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');

		$this->response->setOutput($this->load->view('extension/module/tkmanager', $data));
	}

	protected function validate() {
		if (!$this->user->hasPermission('modify', 'extension/module/tkmanager')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		return !$this->error;
	}
}
Last edited by Dutch Pride Code on Sat Jul 31, 2021 6:01 am, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by straightlight » Sat Jul 31, 2021 5:24 am

EMGX wrote:
Sat Jul 31, 2021 5:12 am
Hi everybody,

Please bear with me as I am trying to learn development and it's not easy. Especially for OpenCart without any decent documentation available. As I am trying to develop a very plain and simple (single instance) admin extension as one of my first attempts, I stumbled upon this problem where the extension just won't get enabled. After saving it the status just restores back to 'disabled'. Does anybody know what I did wrong here? Any help is much appreciated.

My OC version is 3.0.3.7, installed on a local server and the file below is the controller I've created.

Code: Select all

<?php
class ControllerExtensionModuleTkmanager extends Controller {
	private $error = array();

	public function index() {
		$this->load->language('extension/module/tkmanager');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('setting/module');

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->load->model('setting/setting');
            $this->model_setting_setting->editSetting('extension_module_tkmanager', $this->request->post);
            $this->session->data['success'] = $this->language->get('text_success');
            $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));
        }

		if (isset($this->error['warning'])) {
			$data['error_warning'] = $this->error['warning'];
		} else {
			$data['error_warning'] = '';
		}

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_home'),
			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_extension'),
			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)
		);

		if (!isset($this->request->get['module_id'])) {
			$data['breadcrumbs'][] = array(
				'text' => $this->language->get('heading_title'),
				'href' => $this->url->link('extension/module/tkmanager', 'user_token=' . $this->session->data['user_token'], true)
			);
		} else {
			$data['breadcrumbs'][] = array(
				'text' => $this->language->get('heading_title'),
				'href' => $this->url->link('extension/module/tkmanager', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true)
			);
		}

		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);

		if (isset($this->request->post['module_tkmanager_status'])) {
                        $data['module_tkmanager_status'] = $this->request->post['module_tkmanager_status'];
                } else {
                        $data['module_tkmanager_status'] = $this->config->get('module_tkmanager_status');
                }

		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');

		$this->response->setOutput($this->load->view('extension/module/tkmanager', $data));
	}

	protected function validate() {
		if (!$this->user->hasPermission('modify', 'extension/module/tkmanager')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		return !$this->error;
	}
}

Code: Select all

$this->model_setting_setting->editSetting('extension_module_tkmanager', $this->request->post);
for:

Code: Select all

$this->model_setting_setting->editSetting('module_tkmanager', $this->request->post);
Also ensure your tkmanager.twig file uses the module_ prefixes in the mean time. Then, to clear your OC cache when editing with an external tool with UTF-8 without BOM.

You'll probably have to reinstall the extension but also to check in your oc_setting table for the wrong key name: extension_module_tkmanager by removing the row manually.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Dutch Pride Code » Sat Jul 31, 2021 6:01 am

straightlight wrote:
Sat Jul 31, 2021 5:24 am

Code: Select all

$this->model_setting_setting->editSetting('extension_module_tkmanager', $this->request->post);
for:

Code: Select all

$this->model_setting_setting->editSetting('module_tkmanager', $this->request->post);
This did the trick, thank you very much! I'll mark this as solved.
It worked earlier, but I had to re-structure the document and this must have slipped through...

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by straightlight » Sat Jul 31, 2021 6:02 am

EMGX wrote:
Sat Jul 31, 2021 6:01 am
straightlight wrote:
Sat Jul 31, 2021 5:24 am

Code: Select all

$this->model_setting_setting->editSetting('extension_module_tkmanager', $this->request->post);
for:

Code: Select all

$this->model_setting_setting->editSetting('module_tkmanager', $this->request->post);
This did the trick, thank you very much! I'll mark this as solved.
It worked earlier, but I had to re-structure the document and this must have slipped through...
Outstanding!

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: DesignCart, sidclel and 96 guests