本博客基于Opencart2.1.0.1源码,架设在阿里云香港机房!  技术交流QQ群:103164069
//添加字段
alter table oc_product add a_b varchar(50);

vim admin/controller/catalog/product.php//后台的控制器部分
$data['entry_sku'] = $this->language->get('entry_sku');//找到这一行添加下一行,大致在550
$data['entry_a_b'] = $this->language->get('entry_a_b');

//下面的代码原理以此类推
$data['help_sku'] = $this->language->get('help_sku');
$data['help_a_b'] = $this->language->get('help_a_b');

if (isset($this->request->post['sku'])) {
    $data['sku'] = $this->request->post['sku'];
} elseif (!empty($product_info)) {
    $data['sku'] = $product_info['sku'];
} else {
    $data['sku'] = '';
}
if (isset($this->request->post['a_b'])) {
    $data['a_b'] = $this->request->post['a_b'];
} elseif (!empty($product_info)) {
    $data['a_b'] = $product_info['a_b'];
} else {
    $data['a_b'] = '';
}


//语言文件处理
vim admin/language/你的语言包目录/catalog/product.php
$_['entry_sku'] = 'SKU';
$_['entry_a_b'] = 'AB组合商品';//添加的代码

$_['help_sku'] = 'Stock Keeping Unit';
$_['help_a_b'] = 'AB两个组合的可以设置优惠金额!';//添加的代码


//数据处理
vim admin/model/catalog/product.php
$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', a_b = '" . $this->db->escape($data['a_b']) . "', sku = '" . $this->db->escape($data['sku']) .

$this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', a_b = '" . $this->db->escape($data['a_b']) . "',sku = '" . $this->db->escape($data['sku']) .

$data['sku'] = '';
$data['a_b'] = '';//添加的


//后台的前端显示处理
vim admin/view/template/catalog/product_form.tpl
<div class="form-group required">
    <label class="col-sm-2 control-label" for="input-model"><?php echo $entry_model; ?></label>
    <div class="col-sm-10">
        <input type="text" name="model" value="<?php echo $model; ?>" placeholder="<?php echo $entry_model; ?>" id="input-model" class="form-control" />
        <?php if ($error_model) { ?>
            <div class="text-danger"><?php echo $error_model; ?></div>
        <?php } ?>
    </div>
</div>

<div class="form-group">
    <label class="col-sm-2 control-label" for="input-a_b"><span data-toggle="tooltip" title="<?php echo $help_a_b; ?>"><?php echo $entry_a_b; ?></span></label>
    <div class="col-sm-10">
        <input type="text" name="a_b" value="<?php echo $a_b; ?>" placeholder="<?php echo $entry_a_b; ?>" id="input-a_b" class="form-control" />
    </div>
</div>

Write a review

Please login or register to review
浏览次数:1990

Opencart添加额外字段可用于(进货价,商品原地址....)

  • Product Code: 添加额外字段
  • Availability: In Stock
  • ¥0.00