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
Who is online

Users browsing this forum: No registered users and 2 guests