Post by info@jrvsystem.se » Wed Oct 05, 2022 4:27 pm

I am trying to make mainly frontend design changes to our new site.
I like the idé of OCMOD but the search function is crap :( or I am bad at using this. I am really tempted to start editing the core files at this point as it would be so much easier :P

The main problem is the search system of OCMOD. I have seen many similar threads about this issue. But I dont feel there is any clear solution, or am I missing something?
How can find and replace/add/change multi line code?
I guess I can write an operation for every single line individually? But that feels messy. Also, not every single line is unique.

How can I make the OCMOD find this for ex.

Code: Select all

<div class="btn-group">
<button type="button" data-toggle="tooltip" class="btn btn-default" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product_id }}');">
      	<i class="fa fa-heart"></i></button>
<button type="button" data-toggle="tooltip" class="btn btn-default" title="{{ button_compare }}" onclick="compare.add('{{ product_id }}');">
      <i class="fa fa-exchange"></i></button>
</div>
..And remove the code.
Is there a way to do a OCMOD search to ignore linebreaks and spaces reliably?


Posts

Joined
Thu Sep 15, 2022 4:55 pm

Post by pprmkr » Wed Oct 05, 2022 5:24 pm

Try offset:

Code: Select all

	<file path="catalog/view/theme/default/template/product/product.twig">
		<operation>
			<search><![CDATA[<div class="btn-group">]]></search>
			<add position="replace" offset="3"><![CDATA[<!-- lines removed -->]]></add>
		</operation>
	</file>	
Find the search and replace 3 additional lines.

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by DigitCart » Wed Oct 05, 2022 5:48 pm

Hi

Maybe it is better to use CSS to hide this section, Like this:

Code: Select all

.product-thumb .button-group {display: none;}
But if you want to use OCmod, You can comment this section out with two operations and put {# ... #} around it:

Code: Select all

<operation>
	<search><![CDATA[<div class="button-group">]]></search>
	<add position="replace"><![CDATA[{# <div class="button-group">]]></add>
</operation>

<operation>
	<search regex="true"><![CDATA[~(fa-exchange"></i></button>\s*</div>)~]]></search>
	<add position="replace"><![CDATA[$1 #}]]></add>
</operation>
In the second operation I used regex.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by info@jrvsystem.se » Wed Oct 05, 2022 6:21 pm

pprmkr wrote:
Wed Oct 05, 2022 5:24 pm
Try offset:

Code: Select all

	<file path="catalog/view/theme/default/template/product/product.twig">
		<operation>
			<search><![CDATA[<div class="btn-group">]]></search>
			<add position="replace" offset="3"><![CDATA[<!-- lines removed -->]]></add>
		</operation>
	</file>	
Find the search and replace 3 additional lines.
Thank you for solving this issue and explaining how offset work :) work great this time.
But if it gets more complicated? If " <div class="btn-group">" in not unique for e.g.
Is there a way to say, search on line.. move the selection down 2 lines and then offset to get 3 lines for e.g.?
Or is this when index come into play? Search a non-unique line and select the second/thrid or so on?

The docs on OSMOD is not super clear in these operations imo.
Would be great if I could learn how to proper do this.


Posts

Joined
Thu Sep 15, 2022 4:55 pm

Post by pprmkr » Wed Oct 05, 2022 7:15 pm

If a search is not unique, use the search 'index' attribute:

Code: Select all

		<operation>
			<search index="1"><![CDATA[<div class="btn-group">]]></search>
			<add position="replace" offset="3"><![CDATA[<!-- lines removed -->]]></add>
		</operation>
If for example there are 3 '<div class="btn-group">' in the file and you only want to replace the first

See: https://github.com/vqmod/vqmod/wiki/Scripting

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by OSWorX » Thu Oct 06, 2022 12:34 pm

pprmkr wrote:
Wed Oct 05, 2022 7:15 pm
See: https://github.com/vqmod/vqmod/wiki/Scripting
Wrong (not VQMod)!
Question was about OCMod, therefore: https://github.com/opencart/opencart/wi ... tem#search

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


User avatar
Guru Member

Posts

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

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by info@jrvsystem.se » Fri Oct 07, 2022 2:14 pm

Thank you guys, think I have a much better understanding of this now :)
The OCMOD docs does not go into details about index, redex, offset
pprmkr wrote:
Wed Oct 05, 2022 7:15 pm
If a search is not unique, use the search 'index' attribute:

Code: Select all

		<operation>
			<search index="1"><![CDATA[<div class="btn-group">]]></search>
			<add position="replace" offset="3"><![CDATA[<!-- lines removed -->]]></add>
		</operation>
If for example there are 3 '<div class="btn-group">' in the file and you only want to replace the first

See: https://github.com/vqmod/vqmod/wiki/Scripting
For me index starts at 0. Index=1 gives the second result? Anyways, it works :)


Posts

Joined
Thu Sep 15, 2022 4:55 pm

Post by OSWorX » Fri Oct 07, 2022 5:05 pm

info@jrvsystem.se wrote:
Fri Oct 07, 2022 2:14 pm
For me index starts at 0. Index=1 gives the second result?
Correct, compared to VQMod, OCMod starts with 0

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


User avatar
Guru Member

Posts

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

Users browsing this forum: No registered users and 3 guests