Post by CartIdeas » Wed Feb 19, 2025 11:19 pm

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?

User avatar
New member

Posts

Joined
Sun Dec 04, 2016 1:32 pm

Post by Johnathan » Thu Feb 20, 2025 12:09 am

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>

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by CartIdeas » Thu Feb 20, 2025 5:18 pm

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

User avatar
New member

Posts

Joined
Sun Dec 04, 2016 1:32 pm

Post by JNeuhoff » Thu Feb 20, 2025 6:32 pm

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.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by paulfeakins » Thu Feb 20, 2025 7:12 pm

JNeuhoff wrote:
Thu Feb 20, 2025 6:32 pm
it's always better IMHO to implement proper event handlers.
Bear in mind, most developers disagree with this.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by CartIdeas » Thu Feb 20, 2025 8:27 pm

JNeuhoff wrote:
Thu Feb 20, 2025 6:32 pm
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.
Thanks JNeuhoff. I see same issue is reported in Github by some user. For now, I will go back to vQmod

User avatar
New member

Posts

Joined
Sun Dec 04, 2016 1:32 pm

Post by Johnathan » Thu Feb 20, 2025 10:28 pm

Thanks for your testing and letting us know. The advice for others based on this is: ocMod is broken in the initial 4.1.0.0 release so avoid using it for extensions for now.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am

Who is online

Users browsing this forum: paulfeakins and 3 guests