在OpenCart 2.0中创建自定义字段


Create Custom Field in OpenCart 2.0

我是OpenCart的新手,我想知道如何在OpenCart后端(在"产品"部分)添加一个自定义字段(启用了WYSIWYG编辑器的文本区域),然后将其回显到前端(product.tpl)。

我遵循了这个教程&success在后台管理面板中创建了自定义字段,但无法将其回显到前端。

嗨,我发现了这个教程,它与Opencart 2.0兼容:

http://www.php-dev-zone.com/2015/01/how-to-add-custom-product-field-in.html

请不要覆盖核心文件,而是使用vqmod:

http://www.opencart.com/index.php?route=extension/extension/info&extension_id=19501

我建议您使用教程并将所有内容写入实际的核心文件,看看它是否工作(这似乎是正确的)和然后以正确的方式进行操作,并将其全部移动到vqmod。

In:/catalog/controller/product/product.php

您会发现以下内容:

$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');

如果你在那里添加你的字段,例如:

$data['custom_desc'] = $product_info['custom_desc'];

然后在前端,您将能够将其回声到

/catalog/view/theme/default/template/product/product.tpl

作为

$custom_desc;
open admin'model'catalog'product.php
Find addProducts($data) 
function and add below code just after 
`sort_order`
and before     
date_added = NOW()");
your_desc = '" . $this->db->escape($data['your_desc']) . "',
Now find 
editProduct($product_id, $data)` function and add below code just after sort_order and before date_modified = NOW()
your_desc = '" . $this->db->escape($data['your_desc']) . "',
Now open admin'controller'catalog'product.php
Find getForm() function and add below code:
$data['entry_your_desc'] = $this->language->get('entry_your_desc');
Find below code 
if (isset($this->request->post['isbn'])) {
        $data['isbn'] = $this->request->post['isbn'];
    } elseif (!empty($product_info)) {
        $data['isbn'] = $product_info['isbn'];
    } else {
        $data['isbn'] = '';
    }
and add your code just after it
if (isset($this->request->post['your_desc'])) {
 $data['your_desc'] = $this->request->post['your_desc'];
} elseif (isset($product_info)) {
$data['your_desc'] = $product_info['your_desc'];
} else {
$data['your_desc'] = '';
}
Open catalog'view'theme'default'template'product'product.tpl
and find the below code:
<li><?php echo $text_stock; ?> <?php echo $stock; ?></li>
Now add your code after it:
 <li><?php echo $text_your_desc; ?> <?php echo $your_desc; ?></li>
You can place wherever you want to.
Open catalog'language'english'product'product.php
and add your piece of code:
$_['text_your_desc']               = 'Your_description';
Open catalog'controller'product'product.php
Find:
$data['heading_title'] = $product_info['name'];
and add:
$data['text_your_desc'] = $this->language->get('text_your_desc');
Scroll down and find
$data['product_id'] = (int)$this->request->get['product_id'];
now add:
$data['your_desc'] = $product_info['your_desc'];
Open admin'view'template'catalog'product_form.tpl
Find:
<div class="tab-pane" id="tab-data">
Now add your code:
<div class="form-group">
<label class="col-sm-2 control-label" for="input-your_desc">
<?php echo $entry_your_desc; ?>
</label>
<div class="col-sm-10">
<input type="text" name="your_desc" value="<?php echo $your_desc; ?>"      placeholder="<?php echo $entry_your_desc; ?>" id="input-your_desc" class="form- control" />
</div>
</div>
Open catalog'model'catalog'product.php
Find:
if ($query->num_rows) {
and add your code:
'your_desc'            => $query->row['your_desc'],
Open admin'language'english'catalog'product.php
Find :
//Entry
and add :
$_['entry_your_desc']      = 'Your_description';