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

Post by Eleweb92389 » Thu Jun 01, 2023 12:40 am

I don't know if it's a correct practice, but instead of modifying the .twig file, I usually do the modification on the controller, for example (in this case I had made sure that by selecting the province, the city that was part of it appeared):

Code: Select all

<file path="catalog/controller/account/address.php">
<operation>
             <search> <![CDATA[
$this->response->setOutput($this->load->view('account/address_form', $data));]]></search>
             <add position="replace"><![CDATA[
$this->response->setOutput($this->load->view('account/mycustomview', $data));
]]></add>
         </operation>
     </file>
Then I create the mycustomview.twig file in the template path and make all the changes there.

Newbie

Posts

Joined
Mon May 11, 2020 1:42 am
Who is online

Users browsing this forum: gazih and 41 guests