Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to modify OpenCart without touching Core and VQMOD/OCMOD

Is there a better way then using VQMOD/OCMOD to change OpenCart's core files?

Is there some "overrides" folder exists so that I can simply create any PHP file corresponding to the file structure and simply override a core file? (Like it is possible in PrestaShop and Magento).

VQMOD/OCMOD is highly inconvenient. Does someone use any hacks & tricks to achieve the result?

I don't want to touch any core files to keep the system clean and manageable.

Thanks a lot!

like image 929
Serhii Matrunchyk Avatar asked Oct 04 '15 13:10

Serhii Matrunchyk


People also ask

What is vqmod and how does it work with OpenCart?

This results in a "virtual" change to the core during execution without any actual modification to the core files. So it's really useful in the way that it makes the upgrade process of OpenCart smooth even if you've altered the core files. Before we go ahead and learn how to use vQmod with OpenCart, let's see how exactly vQmod works.

What is OpenCart ocmod modification?

In fact, OCMOD is basically a stripped down version of vQmod system. It works in a similar way – modifications are stored in xml files and uploaded to the store via admin panel, then parsed and applied to OpenCart core code. Unlike vQmod, OpenCart has a built-in OCMOD modification uploader and manager.

How do I undo changes to OpenCart core files?

This system doesn’t make any direct changes to the actual OpenCart core files. Because of this, the original files are left intact – you can always undo the changes by simply removing the xml file.

Can I install vqmod If I already have ocmod extensions?

Do not install vQmod, if you have already uploaded OCMOD extensions. You must use only 1 override system, otherwise you will likely get overriding conflicts.


1 Answers

My solution was to modify 1 function (modification()) in the system/startup.php which then allows you to copy any existing PHP file into an 'override' folder and modify it without making changes to the original file.
I'd like to find a way of just replacing the functions changed/added, but the OOP approach in OpenCart doesn't easily allow this.
I've adapted a few OCMOD modules to fit my override method (by applying the module, copying the changed files into my override structure and then removing the module), as I think it's easier to maintain and easier to develop with, and when I create my own modules, I create dummy files in the main structure and the actual files in the 'override' directory, which means all my modifications/additions are in one folder that maintains the structure of the original layout.
It would be possible to generate file diffs that create an OCMOD, but I haven't had time to do that yet. I do mark all my changes, so I can upgrade to newer versions by re-applying my changes manually (which is usually a "good thing" (c), and there is potential to have conflict with other extensions, so manually marking changes means I can apply changes to OCMOD patched files too. My modification function looks like this:

function modification($filename) {
    $mod_dirs = array(
        DIR_MODIFICATION,
        dirname(DIR_SYSTEM).'/override/'    // do this second in case there are other over-rides needed for modules
    );

    foreach($mod_dirs as $mod) {
        if (!defined('DIR_CATALOG')) {
            $file = $mod . 'catalog/' . substr($filename, strlen(DIR_APPLICATION));
        } else {
            $file = $mod . 'admin/' .  substr($filename, strlen(DIR_APPLICATION));
        }

        if (substr($filename, 0, strlen(DIR_SYSTEM)) == DIR_SYSTEM) {
            $file = $mod . 'system/' . substr($filename, strlen(DIR_SYSTEM));
        }

        if (is_file($file)) {
            return $file;
        }
    }

    return $filename;
}

and my directory structure looks like this

/override
/override/admin
/override/catalog
/override/system
like image 121
kevstev01 Avatar answered Sep 19 '22 20:09

kevstev01