Opencart vQmod before, after and replace operation including index and offset

In my previous article I explained how to install vQmod in Opencart and after installing vQmod we will discuss in this article that how to do modification in Opencart using vQmod.

For making changes in opencart file using vQmod we have to create an XML file with below format

<?xml version="1.0" encoding="utf-8"?>
<modification>
<id><![CDATA[Extension Name]]></id>
<version><![CDATA[Extension Version]]></version>
<vqmver><![CDATA[Minimum vQmod version needed]]></vqmver>
<author><![CDATA[Extension Author]]></author>
<website>Extension Author Website</website>
<file name="file URL to modify">
<operation>
<search position="before/after/replace" offset="for replace" index="occurrence no to replace"><![CDATA[code of line for reference of the modification]]></search>
<add><![CDATA[
Line of code to add (before or after) or replace
]]></add>
</operation>
</file>
</modification>

Now lest understand each tag and attribute of this XML file.

  • modification – Main root tag of the xml file containing rest of the definition of vqmod file
    • id – This is the unique name for your extension
    • version – Your extension version
    • vqmver – vQmod extension version needed to run your extension
    • author – Author name
    • website – Extension website
    • file – Details of the file or files to modify and changes to be done
      • name (attribute) – Url of the file to modify for example starting from website root (not with server drive)
      • operation – All details of change to to in specified file(s).
        • search – Specify like of code to take as reference for add or replace operation
          • position – operation type that is adding code before or after specified line or replace specified line
          • offset – This property is used only then position is set to replace. In this property you can specify how many lines after specified line (in search node) need to be replaced.
          • index – Here we can specify which occurrence of code line specified need to be modified
        • add – Here you can specify the code that you want to add or replace as per defined rules.
  1. Add any code before specific line in any file
    <?xml version="1.0" encoding="utf-8"?>
    <modification>
    <id><![CDATA[Add extra information in invoice]]></id>
    <version><![CDATA[1.0.0.0]]></version>
    <vqmver><![CDATA[2.16]]></vqmver>
    <author><![CDATA[edunyte.com]]></author>
    <website>https://edunyte.com</website>
    <file name="admin/view/template/sale/order_invoice.tpl">
    <operation>
    <search position="before" index="1"><![CDATA[<b><?php echo $text_telephone; ?></b> <?php echo $order['store_telephone']; ?><br />]]></search>
    <add><![CDATA[
    <?php echo "Extra Field: Field Value" ?><br />
    ]]></add>
    </operation>
    </file>
    </modification>

    Above code will add an extra line of content on invoice before specified line and for that we have directly added content in invoice template file. Using index attribute we can specify on which occurrence of specify code we want to add content.

  2. Add any code after specific line in any file
    <?xml version="1.0" encoding="utf-8"?>
    <modification>
    <id><![CDATA[Add extra information in invoice]]></id>
    <version><![CDATA[1.0.0.0]]></version>
    <vqmver><![CDATA[2.16]]></vqmver>
    <author><![CDATA[edunyte.com]]></author>
    <website>https://edunyte.com</website>
    <file name="admin/view/template/sale/order_invoice.tpl">
    <operation>
    <search position="after" index="1"><![CDATA[<b><?php echo $text_telephone; ?></b> <?php echo $order['store_telephone']; ?><br />]]></search>
    <add><![CDATA[
    <?php echo "Extra Field: Field Value" ?><br />
    ]]></add>
    </operation>
    </file>
    </modification>

    Above code will add an extra line of content on invoice after specified line and for that we have directly added content in invoice template file. Using index attribute we can specify on which occurrence of specify code we want to add content.

  3. Replace some code with yours in any file
    <?xml version="1.0" encoding="utf-8"?>
    <modification>
    <id><![CDATA[Add extra information in invoice]]></id>
    <version><![CDATA[1.0.0.0]]></version>
    <vqmver><![CDATA[2.16]]></vqmver>
    <author><![CDATA[edunyte.com]]></author>
    <website>https://edunyte.com</website>
    <file name="admin/view/template/sale/order_invoice.tpl">
    <operation>
    <search position="replace" index="1" offset="1"><![CDATA[<b><?php echo $text_telephone; ?></b> <?php echo $order['store_telephone']; ?><br />]]></search>
    <add><![CDATA[
    <?php echo "Extra Field 1: Field Value 1" ?><br />
    <?php echo "Extra Field 2: Field Value 2" ?><br />
    ]]></add>
    </operation>
    </file>
    </modification>

    This is the sample code to replace any line of code with your own code. In above example we have replaced telephone number with our own two line code. See that we have specified offset to 1, this means that this code will replace telephone number along with its next line in invoice template file. As we have explained above that index means which occurrence of specified line of code will be replaced. If we do not specify index attribute then this code will replace all occurrence of specified line in given file.

Leave a Reply

Your email address will not be published.