Notes
Bash script to create OCMOD and vQmod templates with a single command
bash functions i keep in .bash_profile so ocmod foo or vqmod bar creates an OpenCart modification file with the basic template in it.
Bash Scripting
2 minutes
OCMOD and vQmod are both modification systems for Opencart which allow you to change things without overwriting any core files. For Opencart version older than 2.x, vQmod was the king. With version 2.x Opencart launched it’s own modification system to replace the need for installing a separate extension.
The state Opencart is in right now, you’ll find yourself dealing with both vqmod and ocmod scripts. I know i do. So i have written this neat bash script which allows me to type ocmod foo to create a file called foo.ocmod.xml with the basic template ocmod. Same for vqmod, type vqmod bar and it’ll create a file called bar.xml with vqmod tempalte code.
An alternative to this is creating a snippet in your code editor. I prefer the bash way becuase it takes care of creating the file as well.
Here is the bash script. For ease of use i have added these to my .bash_profile so the commands are available globally.
Code
1# ocmod()
2# -------
3ocmod() {
4 touch $1.ocmod.xml
5 echo -e "
6<?xml version="1.0" encoding="utf-8"?>
7<modification>
8 <name>Mod name</name>
9 <version>1.0</version>
10 <author>Aamnah</author>
11 <link>http://aamnah.com</link>
12 <file path="path">
13 <operation>
14 <search><![CDATA[
15
16 ]]></search>
17 <add position="replace"><![CDATA[
18
19 ]]></add>
20 </operation>
21 </file>
22</modification>
23" >> $1.ocmod.xml
24}
25
26# vqmod()
27# -------
28vqmod() {
29touch $1.xml
30echo -e "
31<?xml version="1.0" encoding="UTF-8"?>
32<modification>
33 <id>Name</id>
34 <version>1.0</version>
35 <vqmver>2.X</vqmver>
36 <author>Aamnah</author>
37 <file name="path">
38 <operation info="info">
39 <search position="replace"><![CDATA[
40
41 ]]></search>
42 <add><![CDATA[
43
44 ]]></add>
45 </operation>
46 </file>
47</modification>
48" >> $1.xml
49}
Usage
- Add the code to your
.bash_profile. - To create a vQmod file, type
vqmodand provide the name of the script. For example:vqmod replacewill create replace.xml - To create a OCMOD file, type
ocmodand provide the name of the script. For example:ocmod replacewill create replace.ocmod.xml