How to replace if, else statement in opencart 1.5.x using vQmod

516 Views Asked by At

I have the following code:

if (isset($this->request->get['filter'])) {
        $filter = $this->request->get['filter'];
} else {
        $filter = '';
}

I want to replace it with:

if (isset($this->request->get['attribute'])) {
        $filter = $this->request->get['attribute'];
} else {
        $filter = '';
}

I have tried the following in vQmod folder:

<operation info="After filter request, add attribute request">
            <search position="Replace"><![CDATA[
            if (isset($this->request->get['filter'])) {
            ]]></search>
            <add><![CDATA[
            if (isset($this->request->get['attribute'])) {
                    $filter = $this->request->get['attribute'];
            }
            ]]></add>
</operation>

I checked the vQmod log files and am getting the error: SEARCH NOT FOUND
Can anyone help me to tell me what I have to use in if statement replacement.

2

There are 2 best solutions below

0
On

i tried to use offset into my search attribute like <search position="Replace" offset="2"> but it produce some other error so i decide to use single line search like the following :

            <operation>
                    <search position="replace"><![CDATA[
                    if (isset($this->request->get['filter'])) { 
                    ]]></search>
                    <add><![CDATA[
                    if (isset($this->request->get['attribute'])) {
                    ]]></add>
            </operation>
            <operation>
                    <search position="replace"><![CDATA[
                    $filter = $this->request->get['filter'];
                    ]]></search>
                    <add><![CDATA[
                    $filter = $this->request->get['attribute'];
                    ]]></add>
            </operation>

Hope it helps someone else like me

1
On

The easiest solution would be just to replace both of the get['filter'] values like so

<operation>
    <search position="replace"><[CDATA[get['filter']]]></search>
    <add><[CDATA[get['attribute']]]></add>
</operation>