使用VQmod将自定义字段添加到OpenCart管理员

时间:2013-04-09 16:51:30

标签: opencart vqmod

尝试在OpenCart后台的类别页面中添加简短描述字段。让多个VQmod XML实例在控制器和模型中正常工作,但是尝试使用下面的字段将字段添加到类别页面似乎什么都不做。在category_form.tpl。

中根本没有添加/替换任何内容
<!-- This adds the short description field to the admin category page -->
<file name="admin/view/template/catalog/category_form.tpl">
    <operation>
        <search position="replace"><![CDATA[              <tr>
                <td><?php echo $entry_description; ?></td>
                <td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
              </tr>]]></search>
        <add><![CDATA[              <tr>
                <td><?php echo $entry_short_description; ?></td>
                <td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
              </tr>           
              <tr>
                <td><?php echo $entry_description; ?></td>
                <td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
              </tr>]]></add>
    </operation>
</file>

显然有一个更好的方法,因为我不认为我应该尝试在这里替换所有这些代码,但如果我有人可以检查代码并指出我出错的地方,那将是大。感谢。

更新

顺便说一句,我的XML代码包含在<modification> </modification>中。

我尝试过使用偏移并参考VQmod文档,但仍无法做到这一点......

我试过了: -

<file name="admin/view/template/catalog/category_form.tpl">
    <operation>
        <search position="replace" offset="1"><![CDATA[<td><?php echo $entry_description; ?></td>]]></search>
        <add><![CDATA[              <tr>
                <td><?php echo $entry_short_description; ?></td>
                <td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
              </tr>
              <tr>
                <td><?php echo $entry_description; ?></td>
                <td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
              </tr>]]></add>  
    </operation>
</file>

1 个答案:

答案 0 :(得分:1)

首先应将整个代码包装在

<modification>
    <file ...>
        ....
    </file>
</modification>

其次,您无法搜索多行,您可以搜索特定行,然后使用offset属性

适用于您的案例

<search position="replace" offset="1"><![CDATA[ <td><?php echo $entry_description; ?></td>]]></search>

参考vQmod documentation