I have worked with OCMOD on versions prior to 4.0. Since OCMod is back in 4.1, I want to try it out.
When I place my ocmod.xml file in <opencart root>/system folder and refresh the modifications, modified files get created under <opencart root>/extension/ocmod folder (In older versions it was under storage/modification folder). Though the modified files are created, I don't see them loading. It still loads only the original files and my changes are not in effect. Is there a bug in OCMod. Has anyone made it work?
When I place my ocmod.xml file in <opencart root>/system folder and refresh the modifications, modified files get created under <opencart root>/extension/ocmod folder (In older versions it was under storage/modification folder). Though the modified files are created, I don't see them loading. It still loads only the original files and my changes are not in effect. Is there a bug in OCMod. Has anyone made it work?
Pretty sure you have to also modify the class names in the controller files you are modifying, like the example ocMod that 4.1 includes. Here is the contents of that file:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Modification Test</name>
<description>Modification testing script. Do not use on a production site. This file is only for testing and should only be modified by developers.</description>
<code>default</code>
<version>1.0</version>
<author>OpenCart Ltd</author>
<link>http://www.opencart.com</link>
<!-- Controller Test -->
<file path="admin/controller/catalog/attribute.php">
<operation>
<search>
<![CDATA[Opencart\Admin\Controller\Catalog;]]>
</search>
<add position="replace">
<![CDATA[Opencart\Admin\Controller\Extension\Ocmod\Catalog;]]>
</add>
</operation>
<operation>
<search regex="false">
<![CDATA[$this->load->language('catalog/attribute');]]>
</search>
<add position="before">
<![CDATA[echo 'BEFORE WORKS</br>';]]>
</add>
</operation>
<operation>
<search regex="false">
<![CDATA[$this->load->language('catalog/attribute');]]>
</search>
<add position="after">
<![CDATA[echo 'AFTER WORKS</br>';]]>
</add>
</operation>
<operation>
<search regex="false">
<![CDATA[controller_catalog_attribute]]>
</search>
<add position="replace">
<![CDATA[controller_extension_ocmod_catalog_attribute]]>
</add>
</operation>
<operation>
<search regex="false">
<![CDATA[$this->load->language('catalog/attribute');]]>
</search>
<add position="replace">
<![CDATA[$this->load->language('catalog/attribute');
echo 'REPLACE WORKS</br>';
]]>
</add>
</operation>
</file>
<!-- Model Test -->
<file path="admin/model/catalog/attribute.php">
<operation>
<search>
<![CDATA[Opencart\Admin\Model\Catalog;]]>
</search>
<add position="replace">
<![CDATA[Opencart\Admin\Model\Extension\Ocmod\Catalog;]]>
</add>
</operation>
<operation>
<search regex="false">
<![CDATA[public function addAttribute(array $data): int {]]>
</search>
<add position="before">
<![CDATA[echo 'MODEL BEFORE WORKS</br>';]]>
</add>
</operation>
<operation>
<search regex="false">
<![CDATA[public function addAttribute(array $data): int {]]>
</search>
<add position="after">
<![CDATA[echo 'AFTER WORKS</br>';]]>
</add>
</operation>
</file>
<!-- View Test -->
<file path="admin/view/template/catalog/attribute.twig">
<operation>
<search regex="false">
<![CDATA[<div class="float-end">]]>
</search>
<add position="before">
<![CDATA[ // BEFORE WORKS]]>
</add>
</operation>
<operation>
<search regex="false">
<![CDATA[<div class="float-end">]]>
</search>
<add position="after">
<![CDATA[ // AFTER WORKS]]>
</add>
</operation>
</file>
<!-- Library Test -->
<file path="system/library/template/template.php">
<operation>
<search regex="false">
<![CDATA[include]]>
</search>
<add position="after">
<![CDATA[ // AFTER WORKS]]>
</add>
</operation>
</file>
<!-- Extension Admin Test -->
<file path="extension/opencart/admin/controller/report/customer_order.php">
<operation>
<search>
<![CDATA[Opencart\Admin\Controller\Extension\Opencart\Report;]]>
</search>
<add position="replace">
<![CDATA[Opencart\Admin\Controller\Extension\Ocmod\Extension\Opencart\Report;]]>
</add>
</operation>
<operation>
<search regex="false">
<![CDATA[$this->load->language('extension/opencart/report/customer_order');]]>
</search>
<add position="after">
<![CDATA[echo 'WORKS!';]]>
</add>
</operation>
</file>
<file path="extension/opencart/admin/view/template/report/customer_order_form.twig">
<operation>
<search>
<![CDATA[<h1>]]>
</search>
<add position="after">
<![CDATA[hi]]>
</add>
</operation>
</file>
</modification>
Thanks for the code. After running your ocmod and doing some further investigation, this is what I observed
1. It works if mod is done on index() method. Any change done inside other functions (form,getlist etc) is not getting executed.
You can see that 'BEFORE WORKS' and 'AFTER WORKS' are echoed only once. This comes from index() function and not echoed for the ones in getlist() or form(). Looks like if 'route' points to a method like 'catalog/attribute.form', it does not work but 'catalog/attribute' works
2. There is no need to change the namespace to 'Opencart\Admin\Controller\Extension\Ocmod\Catalog'. The change in index is working fine even without changing the namespace.
3. Changes in model and twig are working fine. There was no need to change the namespace in model as you suggested.
Now the real issue is with modding the non-index methods in the controller file. I wonder if this is a bug in opencart 4.1
1. It works if mod is done on index() method. Any change done inside other functions (form,getlist etc) is not getting executed.
You can see that 'BEFORE WORKS' and 'AFTER WORKS' are echoed only once. This comes from index() function and not echoed for the ones in getlist() or form(). Looks like if 'route' points to a method like 'catalog/attribute.form', it does not work but 'catalog/attribute' works
2. There is no need to change the namespace to 'Opencart\Admin\Controller\Extension\Ocmod\Catalog'. The change in index is working fine even without changing the namespace.
3. Changes in model and twig are working fine. There was no need to change the namespace in model as you suggested.
Now the real issue is with modding the non-index methods in the controller file. I wonder if this is a bug in opencart 4.1
There are a number of known issues reported on the OpenCart github on this. If you really need an XML-based modification system then try VQmod.
Be aware that OCmod and/or VQmod based extensions tend to be of poor quality by many developers, it's always better IMHO to implement proper event handlers.
Be aware that OCmod and/or VQmod based extensions tend to be of poor quality by many developers, it's always better IMHO to implement proper event handlers.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Bear in mind, most developers disagree with this.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Thanks JNeuhoff. I see same issue is reported in Github by some user. For now, I will go back to vQmodJNeuhoff wrote: ↑Thu Feb 20, 2025 6:32 pmThere are a number of known issues reported on the OpenCart github on this. If you really need an XML-based modification system then try VQmod.
Be aware that OCmod and/or VQmod based extensions tend to be of poor quality by many developers, it's always better IMHO to implement proper event handlers.
I am not a developer, I am a nurse, but here are my 2 cents.
All opencart 4 ocmod files are installed inside the extension folder in the root opencart directory
The install.json contains only basic metadata
Opencart 4.1 ocmods do not use XML files, nor do they use SQL for database installation
Installation and DB creation or updates and events register are handled in the admin model file of the ocmod
There is a difference in pathing to opencart 3 that I have not quite been able to get my head around, but it is using pipe | instead of dot .
Loader/Path Rules
DO NOT use /admin/ or /catalog/ in any loader string ($this->load->model(), $this->load->language(), or $this->load->view()).
Everything is loaded relative to the root extension/ocmodname/ folder.
namespace examples
extension/ocmodname/admin/controller/module/ocmodname.php
<php?
namespace Opencart\Admin\Controller\Extension\ocmodname\Module;
class SocialCommunity extends \Opencart\System\Engine\Controller
extension/ocmodname/admin/model/module/ocmodname.php
<php?
namespace Opencart\Admin\Model\Extension\SocialCommunity\Module;
class OcmodName extends \Opencart\System\Engine\Controller
extension/ocmodname/catalog/controller/module/ocmodname.php
<php?
namespace Opencart\Catalog\Controller\Extension\SocialCommunity\Module;
class SocialCommunity extends \Opencart\System\Engine\Controller
extension/ocmodname/catalog/model/module/ocmodname.php
<php?
namespace Opencart\Catalog\Model\Extension\SocialCommunity\Module;
class OcmodName extends \Opencart\System\Engine\Controller
extension/ocmodname/admin/language/en_gb/module/ocmodname.php
no namespace
extension/ocmodname/admin/view/template/module/ocmodname.twig
no namespace
extension/ocmodname/admin/view/template/module/ocmodname_error.twig
extension/ocmodname/catalog/language/en_gb/module/ocmodname.php
extension/ocmodname/catalog/view/javascript/module/custom.min.js
no namespace
extension/ocmodname/catalog/view/stylesheet/module/custom.min.css
no namespace
extension/ocmodname/catalog/view/template/module/ocmodname.twig
no namespace
Very happy to be corrected by those more savvy than I.
All opencart 4 ocmod files are installed inside the extension folder in the root opencart directory
The install.json contains only basic metadata
Opencart 4.1 ocmods do not use XML files, nor do they use SQL for database installation
Installation and DB creation or updates and events register are handled in the admin model file of the ocmod
There is a difference in pathing to opencart 3 that I have not quite been able to get my head around, but it is using pipe | instead of dot .
Loader/Path Rules
DO NOT use /admin/ or /catalog/ in any loader string ($this->load->model(), $this->load->language(), or $this->load->view()).
Everything is loaded relative to the root extension/ocmodname/ folder.
namespace examples
extension/ocmodname/admin/controller/module/ocmodname.php
<php?
namespace Opencart\Admin\Controller\Extension\ocmodname\Module;
class SocialCommunity extends \Opencart\System\Engine\Controller
extension/ocmodname/admin/model/module/ocmodname.php
<php?
namespace Opencart\Admin\Model\Extension\SocialCommunity\Module;
class OcmodName extends \Opencart\System\Engine\Controller
extension/ocmodname/catalog/controller/module/ocmodname.php
<php?
namespace Opencart\Catalog\Controller\Extension\SocialCommunity\Module;
class SocialCommunity extends \Opencart\System\Engine\Controller
extension/ocmodname/catalog/model/module/ocmodname.php
<php?
namespace Opencart\Catalog\Model\Extension\SocialCommunity\Module;
class OcmodName extends \Opencart\System\Engine\Controller
extension/ocmodname/admin/language/en_gb/module/ocmodname.php
no namespace
extension/ocmodname/admin/view/template/module/ocmodname.twig
no namespace
extension/ocmodname/admin/view/template/module/ocmodname_error.twig
extension/ocmodname/catalog/language/en_gb/module/ocmodname.php
extension/ocmodname/catalog/view/javascript/module/custom.min.js
no namespace
extension/ocmodname/catalog/view/stylesheet/module/custom.min.css
no namespace
extension/ocmodname/catalog/view/template/module/ocmodname.twig
no namespace
Very happy to be corrected by those more savvy than I.
Who is online
Users browsing this forum: khnaz35 and 37 guests