opencart

How does the Opencart system/modifications folder function?


I am quite new to OC 2.X and I noticed as I was making changes to the site they werent appearing. When I went to change within the system/modifications folder the changes appeared. I assumed this folder was something new and nothing to do with vqmod. I thought it was a foler that would basically take priority over the core file.

Unfortunately when I installed a plugin it also rebuilt that folder so Ive lost all my changes (Im assuming thats what happened).

Im wondering how does this work overall? Must I make a new extension for every change I would like to make?

I cannot find a clear and concise explanation that explains it for a developers point of view.


Solution

  • You can say that ocmod is same as vqmod but it differs in some ways and provided by default in opencart 2.0 and above version. You have to reset modification cache every time you make any changes to your module to see its effect. Like vqmod ocmod also generates cache files which are placed in modification folder. And files in this folder will get prior then the original one. As i think you were modifying files in modification file you might lose them if you clear modification cache from admin panel.

    You can check system/startup.php file for more understanding.

    // Modification Override
    function modification($filename) {
    if (!defined('DIR_CATALOG')) {
        $file = DIR_MODIFICATION . 'catalog/' . substr($filename, strlen(DIR_APPLICATION));
    } else {
        $file = DIR_MODIFICATION . 'admin/' .  substr($filename, strlen(DIR_APPLICATION));
    }
    
    if (substr($filename, 0, strlen(DIR_SYSTEM)) == DIR_SYSTEM) {
        $file = DIR_MODIFICATION . 'system/' . substr($filename, strlen(DIR_SYSTEM));
    }
    
    if (is_file($file)) {
        return $file;
    }
    
    return $filename;
    }