打开购物车收割台位置错误


Open Cart Header position error

我一直在尝试在opencart中的标题中添加一个位置,我想在那里放一个横幅,好吧。以下是我迄今为止所做的工作。

我在这里打开了横幅模块的语言文件/admin/language/english/module/输入了以下代码

$_['text_headerbanner']       = 'headerbanner';

接下来,我在/admin/view/template/module/打开了横幅模块管理模板,并添加了以下代码。

<?php if ($module['position'] == 'headerbanner') { ?>
<option value="headerbanner" selected="selected"><?php echo $text_headerbanner; ?>       </option>
<?php } else { ?>
<option value="headerbanner"><?php echo $text_headerbanner; ?></option>
<?php } ?>

并在javascript部分添加了圆线140

  html += '      <option value="headerbanner"><?php echo $text_headerbanner; ?></option>';

然后在此处打开模块控制器文件/admin/controller/module/并输入

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

这使我能够将一个新创建的横幅分配到我的管理端的"headerbanner"位置。

现在我继续将位置添加到模板中,我担心这就是不稳定的地方

所以我导航到了/controller/common/home.php并添加

'common/content_middle',

作为倒数第二个数组项,因此末尾使用逗号。然后我在/controlog/controller/common/中创建了一个名为"headerbanner.php"的.php文件,其中包含以下代码-

<?php
class ControllerCommonheaderbanner extends Controller {
public function index() {
    $this->load->model('design/layout');
    $this->load->model('catalog/category');
    $this->load->model('catalog/product');
    $this->load->model('catalog/information');
    if (isset($this->request->get['route'])) {
        $route = $this->request->get['route'];
    } else {
        $route = 'common/home';
    }
    $layout_id = 0;
    if (substr($route, 0, 16) == 'product/category' && isset($this->request- >get['path'])) {
        $path = explode('_', (string)$this->request->get['path']);
        $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
    }
    if (substr($route, 0, 15) == 'product/product' && isset($this->request->get['product_id'])) {
        $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
    }
    if (substr($route, 0, 23) == 'information/information' && isset($this->request->get['information_id'])) {
        $layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
    }
    if (!$layout_id) {
        $layout_id = $this->model_design_layout->getLayout($route);
    }
    if (!$layout_id) {
        $layout_id = $this->config->get('config_layout_id');
    }
    $module_data = array();
    $this->load->model('setting/extension');
    $extensions = $this->model_setting_extension->getExtensions('module');
    foreach ($extensions as $extension) {
        $modules = $this->config->get($extension['code'] . '_module');
        if ($modules) {
            foreach ($modules as $module) {
                if ($module['layout_id'] == $layout_id && $module['position'] == 'headerbanner' && $module['status']) {
                    $module_data[] = array(
                        'code'       => $extension['code'],
                        'setting'    => $module,
                        'sort_order' => $module['sort_order']
                    );
                }
            }
        }
    }
    $sort_order = array();
    foreach ($module_data as $key => $value) {
        $sort_order[$key] = $value['sort_order'];
    }
    array_multisort($sort_order, SORT_ASC, $module_data);
    $this->data['modules'] = array();
    foreach ($module_data as $module) {
        $module = $this->getChild('module/' . $module['code'], $module['setting']);
        if ($module) {
            $this->data['modules'][] = $module;
        }
    }
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/headerbanner.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/common/headerbanner.tpl';
    } else {
        $this->template = 'default/template/common/headerbanner.tpl';
    }
    $this->render();
}
}
?>

因此,我在/view/theme/beautyshop/template/common/中为该代码创建了相应的headerbanner.tpl文件,其中包含该代码-

<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>

然后用-在我的beautyshop头模板中调用它

<?php echo $headerbanner; ?>

我收到这个错误

Notice: Undefined variable: headerbanner in /home/demodeto/public_html/catalog/view/theme/beautyshop/template/common/header.tpl on line 702

header.tpl的代码有1000行长,但这里是被称为的位置的基本片段

?>
<?php echo $headerbanner; ?>
<div id="menu" class="clearfix">
<?
// custom block
if(($this->config->get('beauty_status') == '1')&&($this->config-     >get('beauty_layout_custommenu_block') == 1)&&($this->config-   >get('beauty_layout_custommenu_block_position') == 0))
{
if($this->config->get('beauty_layout_custommenu_block_title')<>'') echo '<li class="li-    custom-block"><a>'.$this->config->get('beauty_layout_custommenu_block_title').'</a><div    class="custom-topmenu-block"><ul><li>'.html_entity_decode($this->config-   >get('beauty_layout_custommenu_block_content')).'</li></ul></div></li><li    class="separator"></li>';
}
?>

我对PHP的了解还不够,无法调试这段代码试图定义变量的地方。任何帮助都将不胜感激。

感谢

答案很简单:您缺少header控制器的子级:

catalog/controller/common/header.php中,几乎在最后找到这个数组:

    $this->children = array(
        'module/language',
        'module/currency',
        'module/cart'
    );

现在你必须添加你的新孩子:

    $this->children = array(
        'module/language',
        'module/currency',
        'module/cart',
        'common/headerbanner'
    );

这应该能胜任工作。