Post by Dutch Pride Code » Thu Nov 18, 2021 7:25 pm

Hi everybody,

As I'm running a couple of OCMOD experiments, somehow none of my changes will actually show up. Yes I refreshed all my caches, the modification simply isn't working. I'm using a default, fresh installation of OpenCart and nothing has been modified inside the TWIG files. When I search for the code directly into the TWIG file, opened in my code editor, I can find it. But OCMOD apparently does not find it, even though I copied the exact code. I created this XML template myself.

Is this the correct way of doing it, or does it require a specific order?
Does OCMOD not recognize TWIG in the code, or what is it?

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
	<name>Extension Name</name>
	<version>1.0</version>
	<author>Author</author>
	<link>https://www.example.com/</link>
	<code>code</code>
	<description>Description</description>
	<file path="admin/view/template/catalog/product_list.twig">
		<operation>
			<search>
				<![CDATA[<td class="text-right">{% if product.special %} <span style="text-decoration: line-through;">{{ product.price }}</span><br/>
                      <div class="text-danger">{{ product.special }}</div>
                      {% else %}
                      {{ product.price }}
                      {% endif %}</td>]]>
			</search>
			<add position="before">
				<![CDATA[<td class="text-right">Buy Price</td>]]>
			</add>
		</operation>
	</file>
</modification>
I've noticed for OC 3.0.3.6 there was a bug with OCMOD.
Is this still a thing in 3.0.3.8 or was it fixed?
What else could be wrong here?

This is the log message:

Code: Select all

MOD: Extension Name

FILE: admin/view/template/catalog/product_list.twig
CODE: <td class="text-right">{% if product.special %} <span style="text-decoration: line-through;">{{ product.price }}</span><br/>
                      <div class="text-danger">{{ product.special }}</div>
                      {% else %}
                      {{ product.price }}
                      {% endif %}</td>
NOT FOUND - OPERATIONS ABORTED!
Last edited by Dutch Pride Code on Thu Nov 18, 2021 7:41 pm, edited 2 times in total.

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by JNeuhoff » Thu Nov 18, 2021 7:32 pm

A search across multiple lines won't work for OCmod.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Dutch Pride Code » Thu Nov 18, 2021 7:34 pm

JNeuhoff wrote:
Thu Nov 18, 2021 7:32 pm
A search across multiple lines won't work for OCmod.
Ahh, thanks! That explains a lot.
But how do I search for a piece of code that has multiple lines?
Do I put everything I want to search for on one line in my XML file?

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by xxvirusxx » Thu Nov 18, 2021 11:01 pm

You can use offset, if you want to replace more lines

Code: Select all

<search><![CDATA[1_line_code]]></search>
And replace 4 lines after that code

Code: Select all

<add position="replace" offset="4"><![CDATA[new_code]]></add>

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by Gergely » Fri Nov 19, 2021 4:13 am

Additionally, you can use index on the <search>. Use <search index="n"> for replacing the n + 1-th match (aka zero indexed). Combine this with offset on the <add>, as xxvirusxx suggested, and that should pretty much cover almost all scenarios.

But for the sake of completeness: you can indeed search for multiple lines using regex <search>. I could not come up with a legitimate scenario off the top of my head where this would be preferred, if something comes to my mind I'll come back with an update. Or if you can tell me why your scenario justifies searching for multiple lines instead of using index and offset, I can explain the method in more detail!

Active Member

Posts

Joined
Wed Sep 30, 2020 7:58 pm

Post by OSWorX » Fri Nov 19, 2021 4:01 pm

Generally it is a bad idea to use OCMod these days.
Why?
Because with OC 4.x OCMod will be not used anymore.
Instead events are the proper method - they are introduced with OC 2.x and are working perfectly with the 3.x branch.

@EMGX I see that you start publishing extensions.
Forget OCMod and change your modifications to events - the earlier you learn that, the easier you will have it later.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member
Online

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by parkookk » Sat Jun 03, 2023 1:28 am

Hi,
On OC3038 in install.xml I add the following lines but in the modifications log page I get error.

-Here is the part of my ocmod extension, the rest operations are all working fine on this extension.

<file path="catalog/controller/product/product.php">
<operation>
<search><![CDATA[$this->response->setOutput($this->load->view('product/product']]></search>
<add position="before"><![CDATA[
if(preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"])){
unset($data['breadcrumbs']);
}
]]></add>
</operation>
</file>

Error in the modifications log in admin panel.
FILE: (sub modification) catalog/controller/product/product.php
CODE: $this->response->setOutput($this->load->view('product/product'
NOT FOUND - OPERATIONS ABORTED!

This is part of the code to remove breadcrumb in mobile view!

User avatar
Active Member

Posts

Joined
Thu Jan 17, 2013 11:56 pm
Location - london

Post by khnaz35 » Sat Jun 03, 2023 2:16 am

parkookk wrote:
Sat Jun 03, 2023 1:28 am
Hi,
On OC3038 in install.xml I add the following lines but in the modifications log page I get error.

-Here is the part of my ocmod extension, the rest operations are all working fine on this extension.

Code: Select all

<file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[$this->response->setOutput($this->load->view('product/product', $data));]]></search>
            <add position="before"><![CDATA[
           if(preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"])){
           unset($data['breadcrumbs']);
           }
            ]]></add>
        </operation>
    </file>
NOT FOUND - OPERATIONS ABORTED!
Use it like this should work!
$this->response->setOutput($this->load->view('product/product', $data));

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by parkookk » Tue Jun 06, 2023 6:07 pm

khnaz35 wrote:
Sat Jun 03, 2023 2:16 am
parkookk wrote:
Sat Jun 03, 2023 1:28 am
Hi,
On OC3038 in install.xml I add the following lines but in the modifications log page I get error.

-Here is the part of my ocmod extension, the rest operations are all working fine on this extension.

Code: Select all

<file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[$this->response->setOutput($this->load->view('product/product', $data));]]></search>
            <add position="before"><![CDATA[
           if(preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"])){
           unset($data['breadcrumbs']);
           }
            ]]></add>
        </operation>
    </file>
NOT FOUND - OPERATIONS ABORTED!
Use it like this should work!
$this->response->setOutput($this->load->view('product/product', $data));
Thanks, it appears that you haven't changed anything. using it like this I get NOT FOUND - OPERATIONS ABORTED! in the log and it's not working. There must be an issue somewhere that is not working with OC3038

User avatar
Active Member

Posts

Joined
Thu Jan 17, 2013 11:56 pm
Location - london
Who is online

Users browsing this forum: alanjones and 80 guests