Page 1 of 1

How to add 2 modifs to the same file in OCMOD file for opencart 2.3.0.2

Posted: Wed Apr 28, 2021 9:44 pm
by oli-infa
I want to add a small snipet of script above a block of script and another one under the same block in the same file. (I can't do a replace because the block is also modified by another extension).

If I had the same file twice I get the message "Modification requires a unique ID code" when installing the extension (Please note that if I remove one of the file section it uploads fine so the issue is not actually with the code ID) Here is what I have:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <name>Spare Parts</name>
    <version>1.0</version>
    <author>Olivier</author>
    <code>spare_parts</code>
    <link></link>

    <file path="admin/model/catalog/product.php">
        <operation error="log">
                <search index="0"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");]]></search>
                <add position="before"><![CDATA[
                                    //spare parts extension

                                    if ( $product_id !=671 )
                                        {//only update the options if this product is not the spare parts

                    ]]>
                </add>
        </operation>
    </file>
  <file path="admin/model/catalog/product.php">
        <operation error="log">
                <search index="1"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");]></search>
                <add position="before"><![CDATA[
                                    }//end except spare parts

                    ]]>
                </add>
        </operation>
    </file>

</modification>
I have tried with using the twice in the same and even use the search and add twice under the one operation but I am getting the same error:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <name>Spare Parts</name>
    <version>1.0</version>
    <author>Olivier</author>
    <code>spare_parts</code>
    <link></link>

    <file path="admin/model/catalog/product.php">
        <operation error="log">
            <search index="0"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");]]></search>
            <add position="before"><![CDATA[
                                //spare parts extension

                                if ( $product_id !=671 )
                                    {//only update the options if this product is not the spare parts

                ]]>
            </add>
        </operation>
        <operation error="log">
            <search index="1"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");]></search>
            <add position="before"><![CDATA[
                                }//end except spare parts

                ]]>
            </add>
        </operation>
    </file>

</modification>

Re: How to add 2 modifs to the same file in OCMOD file for opencart 2.3.0.2

Posted: Wed Apr 28, 2021 10:52 pm
by straightlight
By using an event. If you're not sure how to accomplish this, you could either consult this documentation: https://github.com/opencart/opencart/wiki/Events-System or create a new service request in the Commercial Support section of the forum to get this done as a custom job.

Re: How to add 2 modifs to the same file in OCMOD file for opencart 2.3.0.2

Posted: Thu Apr 29, 2021 4:17 pm
by pprmkr
oli-infa wrote:
Wed Apr 28, 2021 9:44 pm
If I had the same file twice I get the message "Modification requires a unique ID code" when installing the extension (Please note that if I remove one of the file section it uploads fine so the issue is not actually with the code ID) Here is what I have:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <name>Spare Parts</name>
    <version>1.0</version>
    <author>Olivier</author>
    <code>spare_parts</code>
    
<code>spare_parts</code> the same as existing in modifications ! So error is: 'Modification requires a unique ID code'
Change 1 one of them or delete existing!

Re: How to add 2 modifs to the same file in OCMOD file for opencart 2.3.0.2

Posted: Thu Apr 29, 2021 5:04 pm
by oli-infa
<code>spare_parts</code> the same as existing in modifications ! So error is: 'Modification requires a unique ID code'
Change 1 one of them or delete existing!
No it is not, if I do not add the second change to the same file it uploads just fine

Re: How to add 2 modifs to the same file in OCMOD file for opencart 2.3.0.2

Posted: Thu Apr 29, 2021 7:17 pm
by by mona

Code: Select all

<name>Spare Parts part1</name>
    <version>1.0</version>
   <code>spare_parts_part_1</code>
    <author>Olivier</author>

Code: Select all

 <name>Spare Parts part2</name>
    <version>1.0</version>
   <code>spare_parts_part_2</code>
    <author>Olivier</author>

Re: How to add 2 modifs to the same file in OCMOD file for opencart 2.3.0.2

Posted: Tue May 04, 2021 6:42 pm
by oli-infa
The issue was actually simple, I was missing a ] in "<search index="0"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");]]></search>"
All now working with

Code: Select all

<file path="admin/model/catalog/product.php">
        <operation>
            <search index="0"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");]]></search>
            <add position="before" error="log"><![CDATA[
                                //spare parts extension

                                if ( $product_id !=671 )
                                    {//only update the options if this product is not the spare parts

                ]]>
            </add>
        </operation>
        <operation>
            <search index="0"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");]]></search>
            <add position="before" error="log"><![CDATA[
                                }//end except spare parts

                ]]>
            </add>
        </operation>
    </file>

Re: How to add 2 modifs to the same file in OCMOD file for opencart 2.3.0.2

Posted: Tue May 04, 2021 7:06 pm
by straightlight
Now that the issue has been solved, please add: [SOLVED] at the beginning of the subject line on your first post.