0

I am new to OCMod and trying to tidy up my Opencart 3.x store modifications. In many places I need to replace multiple lines of code and I can't seem to get offset to work. Following Digicart's solution: Replace admin TPL files with OCMOD I have the following code.

3 LINES OF CODE TO REPLACE:

<button type="button" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">{{ button_cart }}</span></button>
<button type="button" data-toggle="tooltip" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product.product_id }}');"><i class="fa fa-heart"></i></button>
<button type="button" data-toggle="tooltip" title="{{ button_compare }}" onclick="compare.add('{{ product.product_id }}');"><i class="fa fa-exchange"></i></button>

OCMod CODE:

<file path="catalog/view/theme/default/template/product/category.twig" name="">
<operation info="Move and change add to cart icon and remove text">
<search offset="3"><![CDATA[<button type="button" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">{{ button_cart }}</span></button>]]></search>
    <add position="replace"><![CDATA[
            {% if 1 %}
            <button type="button" data-toggle="tooltip" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product.product_id }}');"><i class="fa fa-heart"></i></button>              
            <button type="button" data-toggle="tooltip" title="Add to Cart" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fa fa-cart-plus"></i></button>
            <button type="button" data-toggle="tooltip" title="{{ button_compare }}" onclick="compare.add('{{ product.product_id }}');"><i class="fa fa-exchange"></i></button>
            {% endif %}
    ]]></add>
</operation>
</file>

Please ignore the redundant "if", actual conditions are removed for testing. The problem is that offset="3" appears to be totally ignored and only the search string is replaced. I end up with 5 buttons instead of 3 re-ordered and modified buttons.

What am I doing wrong?

DigitCart
  • 2,980
  • 2
  • 18
  • 28
onefish
  • 95
  • 1
  • 9

1 Answers1

4

Please move offset to add tag and use 2 instead of 3 (starting from zero):

<add position="replace" offset="2">

I tested with OpenCart 3.0.2.0 and it worked.

For a quicker check, you can upload your file with install.ocmod.xml name in the system/ folder, and then clear the ocmod cache.

<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>test123456</name>
  <code>test123456</code>
  <version>1.0</version>
  <author>test123456</author>
  <link>http://www.opencart.com</link>
<file path="catalog/view/theme/default/template/product/category.twig" name="">
<operation info="Move and change add to cart icon and remove text">
<search><![CDATA[<button type="button" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">{{ button_cart }}</span></button>]]></search>
    <add position="replace" offset="2"><![CDATA[
            {% if 1 %}
            <button type="button" data-toggle="tooltip" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product.product_id }}');"><i class="fa fa-heart"></i></button>              
            <button type="button" data-toggle="tooltip" title="Add to Cart" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fa fa-cart-plus"></i></button>
            <button type="button" data-toggle="tooltip" title="{{ button_compare }}" onclick="compare.add('{{ product.product_id }}');"><i class="fa fa-exchange"></i></button>
            {% endif %}
    ]]></add>
</operation>
</file>
</modification>
DigitCart
  • 2,980
  • 2
  • 18
  • 28
  • As it is often impossible to search unique strings in exactly the beginning of the code to be modified, and multi-line search does not work. Do you happen to know if will work to replace text above the search string? Also can the offset argument be used with the search tag to go to the nth occurrence of a non-unique search string? Sorry, you did answer the original question, it's just left me searching for more ways to control ocmod and there just isn't much information available. – onefish Feb 05 '18 at 12:43
  • Yes you can use `offset`. Now I can not exactly remember that you should use `offset` in the `search` tag or in the `add` tag, but I'm sure you can use `offset`. – DigitCart Feb 05 '18 at 15:36