Post by oli-infa » Wed Apr 28, 2021 9:44 pm

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>

Newbie

Posts

Joined
Wed Jul 22, 2020 4:44 pm

Post by straightlight » Wed Apr 28, 2021 10:52 pm

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by pprmkr » Thu Apr 29, 2021 4:17 pm

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!

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by oli-infa » Thu Apr 29, 2021 5:04 pm

<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

Newbie

Posts

Joined
Wed Jul 22, 2020 4:44 pm

Post by by mona » Thu Apr 29, 2021 7:17 pm

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>

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by oli-infa » Tue May 04, 2021 6:42 pm

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>

Newbie

Posts

Joined
Wed Jul 22, 2020 4:44 pm

Post by straightlight » Tue May 04, 2021 7:06 pm

Now that the issue has been solved, please add: [SOLVED] at the beginning of the subject line on your first post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 159 guests