0

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:

<?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:

    <?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>
user1620090
  • 499
  • 6
  • 19

1 Answers1

0
  <?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="0"><![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 changed index="1" to index="0" When you use for the second add index="1" you close your condition in the next function (public function copyProduct($product_id) {). I assume you need this exception just for public function editProduct($product_id, $data) { If you need it for the second function you must your conditions add separately.

K. B.
  • 1,388
  • 2
  • 13
  • 25
  • Unfortunately it gives the same error with the second index="1", also, the second search does not search the same string as the first and since there are 2 occurences of the same search string if it was working it is likely the snipet would be added in the wrong place – user1620090 Apr 28 '21 at 15:46
  • you must use second index="0" like in my example – K. B. Apr 28 '21 at 18:49
  • it still gives the error Modification requires a unique ID code! (with both index="0") as soon as I add the second tag, if I remove it, the error is gone – user1620090 Apr 29 '21 at 09:09
  • You should uninstall first your old one. Or if you are not able to uninstall, you can find it in your DB via phpmyadmin. oc_modiffication table and remove there your extension. – K. B. Apr 29 '21 at 09:21
  • I have it uninstalled, the issue is not with duplication as the error indicate, the same file using just once uploads just fine – user1620090 Apr 29 '21 at 10:06
  • I did not see in your file any issues... You can try vqmod if you using OC2.3. Just do not forget xml file little bit different for VQMOD – K. B. Apr 29 '21 at 10:18