NewIncredible offer for our exclusive subscribers!Read More
November 23, 2024
Open Cart

OpenCart 4 Single Instance and Multi Instance module

  • September 16, 2024
  • 3 min read
  • 133 Views
OpenCart 4 Single Instance and Multi Instance module

Difference between Single Instance and Multi Instance Module

In a single instance module, you install and can create only one setting, which can be used in multiple places. In a multi-instance module, you can install, create multiple modules, and configure different settings, allowing for the use of varied content in multiple places.

Single Instance OpenCart module

After installation, it will create only one module.

Example of core available single instance OpenCart module are: Account module, Category module, Information module, etc.

Admin section code

$this->load->model(‘setting/setting’);

$this->model_setting_setting->editSetting(‘module_name’, $this->request->post);

The name of the form field should start with the extension initials. For example, for the module, it would be something like name=”module_*****”.

Catalog section code:

The main difference in the controller is in the index method.

public function index() {}

Data are saved in the oc_setting database table.

Multi-Instance OpenCart module

After installation, you can create as many modules as needed.

Example of core available multi instance OpenCart module are: Banner, Featured.

Admin section code

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

if (!isset($this->request->get[‘module_id’])) {
$this->model_setting_module->addModule(‘bestseller’, $this->request->post);
} else {
$this->model_setting_module->editModule($this->request->get[‘module_id’], $this->request->post);
}

Data are saved in the oc_module database table. In the oc_layout database table, the code.module id is stored in the code column.

Some other extra codes for multi-instance opencart module are:

  • Form action link needs to be if-else as per module id.
  • Last Breadcrumbs link need to link to module id link

Extra code:

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

“This is an example of the Featured Module in OpenCart 4.”

Catalog section code

public function index($setting) {}

In the catalog section, the method must accept the $setting parameter. The rest of the code remains the same.

About Author

sagar

Leave a Reply

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