{"id":3591,"date":"2024-09-16T05:19:40","date_gmt":"2024-09-16T05:19:40","guid":{"rendered":"https:\/\/www.rcvtechnologies.com\/blog\/?p=3591"},"modified":"2024-11-13T12:35:22","modified_gmt":"2024-11-13T12:35:22","slug":"opencart-4-single-instance-and-multi-instance-module","status":"publish","type":"post","link":"https:\/\/www.rcvtechnologies.com\/blog\/opencart-4-single-instance-and-multi-instance-module\/","title":{"rendered":"Opencart 4 Single Instance and Multi Instance module"},"content":{"rendered":"<h2>Difference between Single Instance and Multi Instance Module<\/h2>\n<p>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.<\/p>\n<h2><strong>Single Instance Opencart module<\/strong><\/h2>\n<p>After installation, it will create only one module.<\/p>\n<p><strong>Example of core available single instance Opencart module are:<\/strong> Account module, Category module, Information module, etc.<\/p>\n<h3><strong>Admin section code<\/strong><\/h3>\n<div class=\"dm-code-snippet dark no-background  dm-normal-version\" style=\"background-color:#000;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-php\"><\/p>\n<pre class=\"dm-pre-admin-side\">$this-&gt;load-&gt;model(\u2018setting\/setting\u2019);\r\n\r\n$this-&gt;model_setting_setting-&gt;editSetting(\u2018module_name\u2019, $this-&gt;request-&gt;post);<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>The name of the form field should start with the extension initials. For example, for the module, it would be something like name=&#8221;module_*****&#8221;.<\/p>\n<h3><strong>Catalog section code:<\/strong><\/h3>\n<p>The main difference in the controller is in the index method.<br \/>\n<div class=\"dm-code-snippet dark no-background  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-php\"><\/p>\n<pre class=\"dm-pre-admin-side\">public function index() {}<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div><\/p>\n<p>Data are saved in the oc_setting database table.<\/p>\n<h2><strong>Multi-Instance Opencart module<\/strong><\/h2>\n<p>After installation, you can create as many modules as needed.<\/p>\n<p><strong>Example of core available multi instance Opencart module are:<\/strong> Banner, Featured.<\/p>\n<h3><strong>Admin section code<\/strong><\/h3>\n<div class=\"dm-code-snippet dark no-background  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-php\"><\/p>\n<pre class=\"dm-pre-admin-side\">$this-&gt;load-&gt;model(\u2018setting\/module\u2019);\r\n\r\nif (!isset($this-&gt;request-&gt;get[\u2018module_id\u2019])) {\r\n$this-&gt;model_setting_module-&gt;addModule(\u2018bestseller\u2019, $this-&gt;request-&gt;post);\r\n} else {\r\n$this-&gt;model_setting_module-&gt;editModule($this-&gt;request-&gt;get[\u2018module_id\u2019], $this-&gt;request-&gt;post);\r\n}<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>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.<\/p>\n<p>Some other extra codes for multi-instance opencart module are:<\/p>\n<ul>\n<li>Form action link needs to be if-else as per module id.<\/li>\n<li>Last Breadcrumbs link need to link to module id link<\/li>\n<\/ul>\n<p><strong>Extra code:<\/strong><\/p>\n<div class=\"dm-code-snippet dark no-background  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-php\"><\/p>\n<pre class=\"dm-pre-admin-side\">if (!isset($this-&gt;request-&gt;get['module_id'])) {\r\n\t\t\t$data['breadcrumbs'][] = [\r\n\t\t\t\t'text' =&gt; $this-&gt;language-&gt;get('heading_title'),\r\n\t\t\t\t'href' =&gt; $this-&gt;url-&gt;link('extension\/opencart\/module\/featured', 'user_token=' . $this-&gt;session-&gt;data['user_token'])\r\n\t\t\t];\r\n\t\t} else {\r\n\t\t\t$data['breadcrumbs'][] = [\r\n\t\t\t\t'text' =&gt; $this-&gt;language-&gt;get('heading_title'),\r\n\t\t\t\t'href' =&gt; $this-&gt;url-&gt;link('extension\/opencart\/module\/featured', 'user_token=' . $this-&gt;session-&gt;data['user_token'] . '&amp;module_id=' . $this-&gt;request-&gt;get['module_id'])\r\n\t\t\t];\r\n\t\t}<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>&#8220;This is an example of the <strong>Featured Module<\/strong> in Opencart 4.&#8221;<\/p>\n<h3><strong>Catalog section code<\/strong><\/h3>\n<div class=\"dm-code-snippet dark no-background  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-php\"><\/p>\n<pre class=\"dm-pre-admin-side\">public function index($setting) {}<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>In the catalog section, the method must accept the $setting parameter. The rest of the code remains the same.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3491,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[136],"tags":[141,138,140,139],"class_list":["post-3591","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencart","tag-development-opencar4-x-x-x-webapp-ecommerce","tag-opencart-4","tag-php","tag-software-development"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=3591"}],"version-history":[{"count":6,"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3591\/revisions"}],"predecessor-version":[{"id":3853,"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3591\/revisions\/3853"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/media\/3491"}],"wp:attachment":[{"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=3591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=3591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rcvtechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=3591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}