1
votes

I'm currently teaching myself OpenCart and OCMOD. I have a basic understanding on how the system works with creating an XML mod file and uploading this through the modifications interface or directly adding the XML data into the the XML row of the modifications table.

I can successfully, using XML, search for files and either replace lines of code or insert before or after.. The basics basically. I am still yet to learn the full capabilities of XML.

My question, how can I completely override a file? Like I said, I can find, replace or add code to a file by only search for a single line but as in the example below, when I try to search for the whole file and do a simple replace it will not work.

<!-- admin dashboard overide -->
<file path="admin/view/template/common/dashboard.tpl">
  <operation>
    <!-- search the whole file??? -->
    <search>
      <![CDATA[
        <?php echo $header; ?><?php echo $column_left; ?>
        <div id="content">
          <div class="page-header">
            <div class="container-fluid">
              <h1><?php echo $heading_title; ?></h1>
              <ul class="breadcrumb">
                <?php foreach ($breadcrumbs as $breadcrumb) { ?>
                <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
                <?php } ?>
              </ul>
            </div>
          </div>
          <div class="container-fluid">
            <?php if ($error_install) { ?>
            <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_install; ?>
              <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
            <?php } ?>
            <div class="row">
              <div class="col-lg-3 col-md-3 col-sm-6"><?php echo $order; ?></div>
              <div class="col-lg-3 col-md-3 col-sm-6"><?php echo $sale; ?></div>
              <div class="col-lg-3 col-md-3 col-sm-6"><?php echo $customer; ?></div>
              <div class="col-lg-3 col-md-3 col-sm-6"><?php echo $online; ?></div>
            </div>
            <div class="row">
              <div class="col-lg-6 col-md-12 col-sx-12 col-sm-12"><?php echo $map; ?></div>
              <div class="col-lg-6 col-md-12 col-sx-12 col-sm-12"><?php echo $chart; ?></div>
            </div>
            <div class="row">
              <div class="col-lg-4 col-md-12 col-sm-12 col-sx-12"><?php echo $activity; ?></div>
              <div class="col-lg-8 col-md-12 col-sm-12 col-sx-12"> <?php echo $recent; ?> </div>
            </div>
          </div>
        </div>
        <?php echo $footer; ?>
      ]]>
    </search>

    <!-- replace whole file with below -->
    <add position="replace">
      <![CDATA[
        <div class="col-xs-12">OCMOD MODIFIED WORKING????? </div>
      ]]>
    </add>

  </operation>
</file> 
2

2 Answers

1
votes

You can use offset as an attribute for search and number of lines in the file as its value:

offset="35"

This works for me:

<file path="admin/view/template/common/dashboard.tpl">
      <operation>
        <search offset="35">
          <![CDATA[<?php echo $header; ?><?php echo $column_left; ?>]]>
        </search>
        <add position="replace">
          <![CDATA[
            <div class="col-xs-12">OCMOD MODIFIED WORKING????? </div>
          ]]>
        </add>
      </operation>
    </file>
1
votes

Thanks for your reply Mojaba, I did try that and that process did work so thanks, but the way I did it was I created another folder in admin/view/template/ called 'custom' and created a custom dashboard.tpl in it. I then used OCMOD to edit the controller and replace the view it was loading as below. :)

<file path="admin/controller/common/dashboard.php">
<operation>
  <search>
    <![CDATA[
      $this->response->setOutput($this->load->view('common/dashboard', $data));
    ]]>
  </search>
  <add position="replace">
    <![CDATA[
      $this->response->setOutput($this->load->view('custom/dashboard', $data));
    ]]>
  </add>
</operation>