0

我想在一个脚本块上方添加一小段脚本,在同一文件的同一块下添加另一个脚本。(我无法进行替换,因为该块也被另一个扩展修改)。

如果我有两次相同的文件,我会在安装扩展程序时收到消息“修改需要唯一的 ID 代码”(请注意,如果我删除其中一个文件部分,它会正常上传,因此问题实际上与代码 ID 无关)在这里是我所拥有的:

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

我曾尝试在同一操作中使用两次,甚至使用搜索并在一次操作下添加两次,但我得到了同样的错误:

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

1 回答 1

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>

我已更改index="1"index="0" 当您使用第二个添加index="1"时,您在下一个函数(public function copyProduct($product_id) {)中关闭您的条件。我假设你需要这个例外,public function editProduct($product_id, $data) {如果你需要它用于第二个功能,你必须单独添加你的条件。

于 2021-04-28T13:59:50.663 回答