正在加载中...

什么是ocMod鼻祖快速虚拟修改机制vQmod技术及vQmod在OpenCart上的安装

什么是ocMod鼻祖快速虚拟修改机制vQmod技术及vQmod在OpenCart上的安装

ocmod是opencart电商系统的文件更新管理机制,而他的鼻祖vQmod 全称是 Virtual File Modification System 又称快速虚拟MOD)是一个虚拟覆盖系统的设计,以避免原有系统核心文件被修改。这个概念是很简单,它通过创建XML搜索/替换脚本文件,而不是直接更改核心文件。这些脚本文件是在页面加载解析为每个“源”核心文件“包括”或“规定”的php函数加载和资源,然后打补丁的脚本文件的变化,并保存到一个临时文件,然后在执行临时文件,在过程中取代了原来的文件。原来的源文件是永远不会改变。这将实现一个“虚拟”的变化中,在没有任何实际修改的核心文件中执行想要的过程和结果。



<modification>        /* 根 */
    <id>Very simple AJAX live search</id>
    <version>1.0.0</version>
    <vqmver>1.2.3</vqmver>
    <author>n[oO]ne</author>
    <file name="admin/controller/catalog/product.php">  /* 替换的文件名*/
        <operation>
            <search position="after">  /*ater: 在寻找到的字符串后面增加;before:在寻找到的字符串前面增加;replace:替换寻找到的字符串*/
                <![CDATA[
            $this->data['products'][] = array(  /* 查找的字符串*/
                ]]>
            </search>
            <add>
                <![CDATA[
            'sku'      => $result['sku'],   /* 增加或替换的字符串*/
            'upc'      => $result['upc'],
                ]]>
            </add>
        </operation>
    </file>

看到这里大家就明白了,vqmod的机制就是当执行某一程序,先查找vqmod/目录下的所有xml文件,有没有;若没有,就正常执行;若有,就按这个xml文件的说明替换掉源文件,再执行这替换后的文件。所以系统会有一个位置存储这些替换后生成的文件,这个位置就是vqmod/vqcache

vQmod在opencart上的安装

下载

官方下载:官方下载页

  vqmod-2.3.2-opencart.zip (13.4 KB, 391 次)

安装

http://code.google.com/p/vqmod/wiki/Install_OpenCart

1.将压缩包解压后把文件上传后上传到网站根目录

2.将vqmod/vqcache文件夹权限修改为755或者777

3.浏览器中执行http://www.yoursite.com/vqmod/install

4.有安装成功的提示VQMOD HAS BEEN INSTALLED ON YOUR SYSTEM!

以下是一篇关于OCMOD及vqMOD的对比介绍英文原文,供有能力的朋友参考。

Modifying OpenCart: vQmod vs OCMOD 

Having two or more ways to do something can be useful, but it isn't always the case. When it comes to OpenCart, there are four ways to modify its core functionality: vQmod, OCMOD, Override Engine and Event Handlers. Let’s take a quick look at vQmod and OCMOD and the differences between these two.

What is vQmod and How Does it Work?

vQmod (or Virtual Quick Mod) is the most widely used of the four override systems available today. If you're using MultiMerch, you probably know that we only use vQmod for OpenCart core modifications.

It's actually quite simple – search/replace code modifications are specified as separate xml files (see the syntax examples here). vQmod then parses the xml files during page load and applies the modifications to the target files. The result is saved as a temporary modified file, which is then loaded by OpenCart instead of the original one.

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

vQmod lets you apply multiple modifications to same files, making it possible to install multiple vQmod-powered extensions (usually) without conflicts. The system also has a variety of options for finding/replacing code, error handling, positions, indexing and more. If an error occurs, OpenCart will simply fall back to the original source file.

The drawback is that vQmod isn't part of OpenCart – it needs to be installed separately. If you're creating your own vQmod-powered extensions, you'll need to make sure your clients have vQmod installed on their servers. If it's not present, the extension will not work correctly. (The good thing is – the installation process is really simple: upload, run the installer, done)

Finally, even though vQmod was designed to use it with OpenCart, it can also be used separately – there is a standalone version of vQmod available for download that can be integrated into any custom project unrelated to OpenCart.

Is OCMOD a Better Alternative?

If vQmod is so awesome, why would you need something else? Well, the idea was to have something simpler built into OpenCart and available by default. Or, as Daniel Kerr, the main guy behind OpenCart, put it: "The problem also is vQmod, I just don't like how there are a lot of unnecessary features."

In fact, OCMOD is basically a stripped down version of vQmod system built into OpenCart. It works in a similar way – modifications are stored in xml files and uploaded to the store, then parsed and applied to OpenCart core code. Unlike vQmod, OpenCart has a built-in OCMOD modification uploader and manager. In addition to this, OCMOD allows you to specify extra SQL and PHP code to be executed during modification installation in separate install.php and install.sql files.

There are a few drawbacks compared to the original vQmod, though. This includes a few missing advanced search/replacement modifiers such as top, bottom, iafter and ibefore, as well as partial line matching and a few other things. In addition to this, OpenCart's modification cache needs to be refreshed every time there are changes to OCMOD files, which may slow down development, and OCMOD log files aren't as informative as vQmod's.

Because of these differences and the lack of a clear benefit, OCMOD hasn't received wider adoption (with some of the community calling it a “poor man’s vQmod”) and vQmod is still used by many OpenCart developers who are reluctant to spend time and effort converting their mods. (If you feel like converting, however, see a great vQmod to OCMOD conversion guide by an OpenCart developer rph here).

Conclusion

Both vQmod and OCMOD are meant to be used for the same purpose and both have their pros and cons (feel free to check this developer discussion thread on OpenCart forums). The choice is yours, though. We at MultiMerch still use vQmod – mostly because there are quite a bit of modifications in MultiMerch Marketplace. If you're starting something from scratch, you may as well try OCMOD first since it's part of OpenCart. You can always switch later!

vQmod
+ mature, stable and robust system – original version released in 2010
+ clear documentation
+ simple modification syntax and deployment
- not part of OpenCart core – needs to be installed separately

OCMOD
+ part of OpenCart core – no additional installation needed
+ modification installer integrated into OpenCart
+ "execute during installation" scripts
- a few features missing compared to vQmod
- relatively new system with no clear development roadmap

 

Martin Boze

About the authorMartin Boze is the Founder of MultiMerch Marketplace. I also love skydiving, motorcycles and space. And other cool things.



返回上一页