![Creating modifiers in OpenCard](/uploads/blog/ocmod/ocmod.jpg)
Creating modifiers in OpenCard is easy ?
![Creating modifiers in OpenCard](/uploads/blog/ocmod/ocmod.jpg)
Creating modifiers in OpenCard is easy ?
Starting code;
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>name</name>
<version>0.1</version>
<author>CoderUA</author>
<link>https://example.com</link>
<code>name_code</code>
<description>Example description</description>
<file path="">
<operation>
<search><![CDATA[ ]]></search>
<add position="after"><![CDATA[
]]></add>
</operation>
</file>
</modification>
Tags.
You can specify multiple file locations by separating them with commas. The modification system uses the PHP glob function.
Direct path to the file.
<file path="admin/controller/common/column_left.php">
Using curly brackets allows you to select multiple files and not repeat a code operation several times.
<file path="system/engine/action.php|system/engine/loader.php|system/library/config.php|system/library/language.php">
also allows groups
<file path="system/{engine,library}/{action,loader,config,language}*.php">
Note that all file paths must start with admin, catalog, or system. You can also use the template to search multiple directories and files.
<search>
Allowed attributes
- trim=”(true|false)”
- regex=”(true|false)”
- index=”(number)”
Example
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Modification Default</name>
<version>1.0</version>
<author>CoderUA</author>
<link>http://www.opencart.com</link>
<code>webocreation_mod_1</code>
<file path="catalog/controller/common/home.php">
<operation>
<search trim="true|false" index="1"><![CDATA[
$data['column_left'] = $this->load->controller('common/column_left');
]]></search>
<add position="replace" offset="1"><![CDATA[
test123
]]></add>
</operation>
</file>
</modification>
<add>
The code you want to replace the search with.
Allowed Attributes
- trim=”(true|false)”
- position=”(replace|before|after)”
- offset=”(number)”
(the comment position cannot be used if the regex search attribute is set to true).
Приклад
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Modification Default</name>
<version>1.0</version>
<author>CoderUA</author>
<code>webocreation_modification_default</code>
<link>http://www.opencart.com</link>
<file path="catalog/controller/common/home.php">
<operation>
<search trim="true|false"><![CDATA[
$data['column_left'] = $this->load->controller('common/column_left');
]]></search>
<add position="replace|before|after" trim="true|false" offset="2"><![CDATA[
test123
]]></add>
</operation>
</file>
</modification>
Regex
Дозволені атрибути
- limit=”(number)”
Example:
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Regex Example</name>
<version>1.0</version>
<author>CoderUA</author>
<code>webocreation_regexexample</code>
<link>http://www.opencart.com</link>
<file path="system/{engine,library}/{action,loader,config,language}*.php">
<operation>
<search regex="true" limit="1"><![CDATA[
~(require|include)(_once)?\(([^)]+)~
]]></search>
<add><![CDATA[
$1$2(modification($3)
]]></add>
</operation>
</file>
</modification>
If you're using a regular expression, you can't use the position, trim, or offset attributes because they're handled by the regular expression code you write. The limit attribute is still available.
If, for example, you want to change the 3rd "foo" to "bar" in the next line:
lorem ifoopsum foo lor foor ipsum foo dolor foo
^1 ^2 ^3 ^4 ^5
Launch
s/\(.\{-}\zsfoo\)\{3}/bar/
The result.:
lorem ifoopsum foo lor barr ipsum foo dolor foo
^1 ^2 ^3=bar ^4 ^5
Another example of using regex
Translated by Джерело