添加额外的产品选项卡 (OpenCart)

Add extra product tab (OpenCart)

OpenCart 版本 2.1.0.2

示例为 here。有 3 个产品选项卡(描述、评论、自定义选项卡)。

我需要添加另一个选项卡,以便分别从管理面板为每个产品添加信息。

  1. 我已经添加到 /catalog/view/theme/default/product/product.tpl

    <li><a href="#tab-video" data-toggle="tab"><?php echo $tab_video; ?></a></li>
    
  2. 到/catalog/language/*/product/product.php

    $_['tab_video'] = 'Video';
    
  3. 到 /catalog/controller/product/product.php

    $data['tab_video'] = $this->language->get('tab_video');
    
  4. 我将代码添加到 admin/view/template/catalog/product_form.tpl

    <label class="col-sm-2 control-label" for="input-video<?php echo $language['language_id']; ?>"><?php echo $entry_video; ?></label>
    <div class="col-sm-10">
      <textarea name="product_video[<?php echo $language['language_id']; ?>][video]" placeholder="<?php echo $entry_video; ?>" id="input-video<?php echo $language['language_id']; ?>">
        <?php echo isset($product_video[$language['language_id']]) ? $product_video[$language['language_id']]['video'] : ''; ?>
      </textarea>
    </div>
    

现在我在产品页面上看到了该选项卡,在管理面板中看到了该字段。但是我有这个错误:

Notice: Undefined variable: entry_video in /home/morganit/morgan-it.com.ua/italiavogs/admin/view/template/catalog/product_form.tpl on line 66

如何将它连接到数据库以及如何使其正常工作?

首先你需要在语言中定义变量 $entry_video 以及像这样的控制器:

1 - 语言 /admin/language/*/catalog/product.php

$_['entry_video'] = 'Video';

2-控制器/admin/controller/catalog/product.php

正在行动getForm()

$data['entry_video'] = $this->language->get('entry_video');

在 product_description table

中添加 1 列名为视频(键入文本)

3 - 模型 /admin/model/catalog/product.php

在行动getProductDescriptions()meta_keyword => $result['meta_keyword']

之后添加以下内容
'video'     => $result['video'],

现在在 /admin/model/catalog/product.php 中进行操作 addProduct() & editProduct() 修改

foreach ($data['product_description'] as $language_id => $value) {
            $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
        }

AS

foreach ($data['product_description'] as $language_id => $value) {
            $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', video = '" . $this->db->escape($value['video']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
        }    

4 - 查看

现在 admin/view/template/catalog/product_form.tpl(靠近 87-92 号的常规选项卡行)在

之后
   <div class="form-group">
                    <label class="col-sm-2 control-label" for="input-tag<?php echo $language['language_id']; ?>"><span data-toggle="tooltip" title="<?php echo $help_tag; ?>"><?php echo $entry_tag; ?></span></label>
                    <div class="col-sm-10">
                      <input type="text" name="product_description[<?php echo $language['language_id']; ?>][tag]" value="<?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['tag'] : ''; ?>" placeholder="<?php echo $entry_tag; ?>" id="input-tag<?php echo $language['language_id']; ?>" class="form-control" />
                    </div>
                  </div>

添加关注

<div class="form-group">
                    <label class="col-sm-2 control-label" for="nput-video<?php echo $language['language_id']; ?>"><?php echo $entry_video; ?></label>
                    <div class="col-sm-10">
                      <textarea name="product_description[<?php echo $language['language_id']; ?>][video]" rows="5" placeholder="<?php echo $entry_video; ?>" id="input-video<?php echo $language['language_id']; ?>" class="form-control"><?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['video'] : ''; ?></textarea>
                    </div>
                  </div>

现在,您只需调用列视频(来自 product_description table)并在您的自定义选项卡(在前端)中显示它,即可获取前端的自定义文本值,只需按照以下步骤操作即可:

1- /catalog/language/*/product/product.php/

添加

$_['tab_video'] = 'Video';

2- /目录/控制器/product/product.php

添加

$data['product_video'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']);
                $this->load->model('localisation/language');
                $data['languages'] = $this->model_localisation_language->getLanguages();

3 - /catalog/model/catalog/product.php

添加

public function getProductDescriptions($product_id) {
    $product_description_data = array();

    $query = $this->db->query("SELECT video,language_id FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");

    foreach ($query->rows as $result) {
        $product_description_data[$result['language_id']] = array(
            'video'            => $result['video'],   
        );
    }

    return $product_description_data;
}

4 - /catalog/view/theme/*/默认/模板/product/product.tpl/

添加

   <div class="tab-pane" id="tab-video">
                <label class="col-sm-2 control-label" for="input-video<?php echo $language['language_id']; ?>"><?php echo $tab_video; ?></label>
<div class="col-sm-10">
  <textarea name="product_video[<?php echo $language['language_id']; ?>][video]"  id="input-video<?php echo $language['language_id']; ?>">
  <?php foreach($languages as $language) { ?>
   <?php echo isset($product_video[$language['language_id']]) ? $product_video[$language['language_id']]['video'] : ''; ?>
  </textarea>
</div>
<?php } ?>
                </div>