Page 1 of 1
frustrating using OCMOD search on multi line code OC3038
Posted: Wed Oct 05, 2022 4:27 pm
by info@jrvsystem.se
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
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?
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Wed Oct 05, 2022 5:24 pm
by pprmkr
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.
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Wed Oct 05, 2022 5:48 pm
by DigitCart
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.
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Wed Oct 05, 2022 6:21 pm
by info@jrvsystem.se
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.
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Wed Oct 05, 2022 7:15 pm
by pprmkr
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
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Thu Oct 06, 2022 12:34 pm
by OSWorX
Wrong (not VQMod)!
Question was about OCMod, therefore:
https://github.com/opencart/opencart/wi ... tem#search
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Thu Oct 06, 2022 1:48 pm
by pprmkr
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Fri Oct 07, 2022 2:14 pm
by info@jrvsystem.se
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
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Fri Oct 07, 2022 5:05 pm
by OSWorX
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
Re: frustrating using OCMOD search on multi line code OC3038
Posted: Thu Jun 01, 2023 12:40 am
by Eleweb92389
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.