Post by szabolevi98 » Sat Apr 12, 2025 2:27 am

Hello,

I have this example ocmod:

Code: Select all

<modification>
    <name>OpenCart Log Cleaner Simple</name>
    <code>log_cleaner_simple</code>
    <version>1.0.0</version>
    <author>szabolevi98</author>
    <link>https://levente.net</link>
    <file path="system/library/log.php">
        <operation error="log">
            <search>
                <![CDATA[public function __construct(string $filename) {]]>
            </search>
            <add position="after">
                <![CDATA[        if (file_exists(DIR_LOGS . $filename) && filesize(DIR_LOGS . $filename) > ((defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 50) * 1024 * 1024)) {
            file_put_contents(DIR_LOGS . $filename, '');
        }]]>
            </add>
        </operation>
        <operation error="log">
            <search>
                <![CDATA[namespace Opencart\System\Library;]]>
            </search>
            <add position="replace">
                <![CDATA[namespace Opencart\System\Library\Extension\Ocmod;]]>
            </add>
        </operation>
    </file>
</modification>

File created on /extension/ocmod/system/library/log.php but never executed.
I'm using phpStorm as IDE and I have xdebug installed, so I checked that this file never called. It calls the original file at /system/library/log.php.
What is the error here? I even modified the namespace. (I tried without it also)
Or it is not possible to make ocmod for system/library, it is only possible for controllers and models?

User avatar
Newbie

Posts

Joined
Thu Mar 03, 2022 6:10 pm

Post by MaxD » Mon Apr 14, 2025 3:47 pm

At 4.1.0.3, for me modding plain controllers does not work still, the original controller file is called.

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm


Post by wilito2560 » Mon Jun 23, 2025 2:33 pm

Hello,

Fix the OCMOD to Modify the Original File Directly
Instead of trying to move or create a file in /extension/ocmod/system/..., simply target and modify the original file in place:

Code: Select all

<modification>
    <name>OpenCart Log Cleaner Simple</name>
    <code>log_cleaner_simple</code>
    <version>1.0.0</version>
    <author>szabolevi98</author>
    <link>https://levente.net</link>

    <file path="system/library/log.php">
        <operation>
            <search><![CDATA[public function __construct(string $filename) {]]></search>
            <add position="after">
                <![CDATA[
                if (file_exists(DIR_LOGS . $filename) && filesize(DIR_LOGS . $filename) > ((defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 50) * 1024 * 1024)) {
                    file_put_contents(DIR_LOGS . $filename, '');
                }
                ]]>
            </add>
        </operation>
    </file>
</modification>
Remove This:

Code: Select all

<operation>
    <search><![CDATA[namespace Opencart\System\Library;]]></search>
    <add position="replace"><![CDATA[namespace Opencart\System\Library\Extension\Ocmod;]]></add>
</operation>
After Fixing the XML
Upload your new .ocmod.xml via Extensions > Modifications.

Click Refresh in the Modifications page.

Optionally clear cache: go to Dashboard > Developer Settings > Clear Theme & SASS Cache.

Confirm changes in:
/system/storage/modification/system/library/log.php
This is where the modified file gets generated.

Best Regard,
Helen

Newbie

Posts

Joined
Mon Jun 23, 2025 2:26 pm

Post by DesignCart » Sat Aug 30, 2025 1:03 am

I need to write a modification for the header.php controller. Does OC intend to introduce this feature at all, or has it been permanently abandoned?

Tworzenie sklepów internetowych | Portfolio | Cennik | O mnie


User avatar
Active Member

Posts

Joined
Thu Nov 10, 2016 2:06 pm
Location - Gubin

Post by khnaz35 » Sat Aug 30, 2025 4:56 pm

Not my first choice but you can try alternative of OCMOD
https://github.com/stalker780/opencart-vqmod-manager

Or lean toward using event system in OC

Got a burning question at 3 AM that even Google shrugs at? There’s a not-so-secret inbox that might just have your answer: khnaz35@gmail.com
Breathe in some nature while you're at it. It’s cheaper than therapy. :-*

Feel free to sling a bear my way via PayPal @ khnaz35@gmail.com


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by OSWorX » Sat Aug 30, 2025 5:49 pm

DesignCart wrote:
Sat Aug 30, 2025 1:03 am
I need to write a modification for the header.php controller. Does OC intend to introduce this feature at all, or has it been permanently abandoned?
Easely done with an event: viewtopic.php?t=227710

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 4 guests