Search code examples
opencartocmod

Opencart / OCmod - Search for one OR another line of code


I'm working on a modification for Opencart, using OCmod. Initially, I started writing it for Opencart 2 (It's actually done and working). Now, I'm upgrating it for OC3.

Here's a quick example of what's going wrong.

Previously, I wrote this for OC2:

<operation>
    <search><![CDATA[
        'status' => ($result['status']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
    ]]></search>
    <add position="replace"><![CDATA[
        'status' => ($result['status']),
    ]]></add>
</operation>

The problem is: As of OC3, this part of the code:

'status' => ($result['status']) ...

has been changed to:

'status' => $result['status'] ...

Therefore, the line will not be found, and the replacement will not be made.

For that reason, if I wish to publish my modification for both versions, I'll have to release two different versions of my modification.

I wonder if there's a way of telling OCmod to search for one of the two lines, and then change the one it finds. That way, I could have only one code working for both versions.

I've tried duplicating that piece of code, making it look for both lines, but my modification stops working since one of the lines is not found.

Any ideas on how to go around this?


Solution

  • SOLVED

    It turns out, OCmod allows you to select just a piece of the code, not just full lines. Since I only needed to delete the last portion of the line, I did this:

    <operation>
        <search><![CDATA[
            ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
        ]]></search>
        <add position="replace"><![CDATA[
            ,
        ]]></add>
    </operation>
    

    Also, if it helps anyone, having OCmod to look for a file that doesn't exist will not cause an error. That was helpful since file "product_list.tpl" has been renamed to "product_list.twig" in Opencart 3. So, in my install.xml file, I was able to write a modification for both files, even though one of them will not be found depending on the OpenCart version.