{"id":49,"date":"2021-02-13T17:43:49","date_gmt":"2021-02-13T17:43:49","guid":{"rendered":"https:\/\/jonrocket.com\/zencart\/?p=49"},"modified":"2021-02-13T17:47:42","modified_gmt":"2021-02-13T17:47:42","slug":"under-the-hood-creating-the-plug-in","status":"publish","type":"post","link":"https:\/\/jonrocket.com\/zencart\/2021\/02\/13\/under-the-hood-creating-the-plug-in\/","title":{"rendered":"eBay Integration &#8211; Creating the Plug-In"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"459\" height=\"418\" src=\"https:\/\/jonrocket.com\/zencart\/wp-content\/uploads\/2021\/02\/zencart-plugin.png\" alt=\"\" class=\"wp-image-50\" srcset=\"https:\/\/jonrocket.com\/zencart\/wp-content\/uploads\/2021\/02\/zencart-plugin.png 459w, https:\/\/jonrocket.com\/zencart\/wp-content\/uploads\/2021\/02\/zencart-plugin-300x273.png 300w\" sizes=\"auto, (max-width: 459px) 100vw, 459px\" \/><\/figure>\n\n\n\n<p>The latest version of Zen Cart includes a <a href=\"https:\/\/docs.zen-cart.com\/dev\/plugins\/encapsulated_plugins\/\">new method of defining plug-ins<\/a>.  Even though it is still being developed, subject to change, and not well documented,  I&#8217;m using it for my eBay Integration plug-in because it has a big advantage over the older method of defining a plug-in.<\/p>\n\n\n\n<p>In the past, a plug-in&#8217;s files were stored in multiple places in the Zen Cart directory structure and some plug-in files actually overwrote existing &#8220;core&#8221; files.  This made updating and maintaining both the plug-in and Zen Cart difficult.  The new method puts the plug-in files in one area and offers a cleaner way to upgrade.<\/p>\n\n\n\n<p>Unfortunately, due to some limitations of the plug-in manager, I have had to put some of the eBay Integration files in other locations. But, I have developed the plug-in so that it does not require modifying any of the Zen Cart core files or any of the existing database tables.  This will make maintenance and upgrading easier and less risky.<\/p>\n\n\n\n<p>The plug-in is &#8220;installed&#8221; in the Zen Cart <strong>zc_plugins<\/strong> folder in a folder called <strong>ebayintegration<\/strong> which contains a folder called <strong>v1.0.0<\/strong> which, obviously, is the version of the plug-in . In that folder is a file called <strong>manifest.php<\/strong> which describes the plugin.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n<span class=\"hljs-keyword\">return<\/span> &#91;\n    <span class=\"hljs-string\">'pluginVersion'<\/span> =&gt; <span class=\"hljs-string\">'v1.0.0'<\/span>,\n    <span class=\"hljs-string\">'pluginName'<\/span> =&gt; <span class=\"hljs-string\">'eBay Integration'<\/span>,\n    <span class=\"hljs-string\">'pluginDescription'<\/span> =&gt; <span class=\"hljs-string\">'eBay Integration for Zen Cart.'<\/span>,\n    <span class=\"hljs-string\">'pluginAuthor'<\/span> =&gt; <span class=\"hljs-string\">'Roger Smith (sales@jonrocket.com)'<\/span>,\n    <span class=\"hljs-string\">'pluginId'<\/span> =&gt; <span class=\"hljs-number\">1818<\/span>, <span class=\"hljs-comment\">\/\/ ID from Zen Cart forum<\/span>\n    <span class=\"hljs-string\">'zcVersions'<\/span> =&gt; &#91;<span class=\"hljs-string\">'v157'<\/span>],\n    <span class=\"hljs-string\">'changelog'<\/span> =&gt; <span class=\"hljs-string\">''<\/span>, <span class=\"hljs-comment\">\/\/ online URL (eg github release tag page, or changelog file there) or local filename only, ie: changelog.txt (in same dir as this manifest file)<\/span>\n    <span class=\"hljs-string\">'github_repo'<\/span> =&gt; <span class=\"hljs-string\">''<\/span>, <span class=\"hljs-comment\">\/\/ url<\/span>\n    <span class=\"hljs-string\">'pluginGroups'<\/span> =&gt; &#91;],\n];\n<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Zen Cart uses the manifest to install and enable the plug-in through the Zen Cart admin <a href=\"https:\/\/docs.zen-cart.com\/user\/admin_pages\/modules\/plugin_manager\/\">Plug-in Manager<\/a>. As you can see, it defines things like the name of the plug-in, developer, and version number.<\/p>\n\n\n\n<p>Also in the <strong><strong>v1.0.0<\/strong><\/strong> folder are two subfolders &#8211; <strong>installer<\/strong> and <strong>admin<\/strong>.<\/p>\n\n\n\n<p>The <strong>installer<\/strong> folder contains a PHP file called <strong>ScriptedInstaller.php<\/strong>.  As the name implies, this is code that installs the plug-in. It calls a method to register the eBay Integration administration page and add it to the Zen Cart <strong>Tools<\/strong> menu.<\/p>\n\n\n\n<p>The <strong>admin<\/strong> folder contains subfolders that mirror the structure under the main Zen Cart <strong>admin<\/strong> folder (which you should have renamed).  In the <strong>admin<\/strong> folder is the code for the eBay Integration administration page, <strong>ebayintegration.php<\/strong>.  <\/p>\n\n\n\n<p>Under the <strong>admin<\/strong> folder is an <strong>include<\/strong> folder.  As mentioned earlier, this folder mirrors the <strong>admin\/includes<\/strong> folder in the Zen Cart root folder.  So, the <strong>includes<\/strong> folder contains folders that define the classes, CSS, images, language, and other stuff used by the plug-in. <\/p>\n\n\n\n<p>I&#8217;m not sharing the code, yet, because it is still under construction.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The latest version of Zen Cart includes a new method of defining plug-ins. Even though it is still being developed, subject to change, and not well documented, I&#8217;m using it for my eBay Integration plug-in because it has a big advantage over the older method of defining a plug-in. In the past, a plug-in&#8217;s files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[4,5,11,6],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-ebay-integration","tag-ebay","tag-ebay-integration","tag-plug-in","tag-zen-cart"],"_links":{"self":[{"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":3,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":54,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/posts\/49\/revisions\/54"}],"wp:attachment":[{"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jonrocket.com\/zencart\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}