Reputation: 627
I have been trying to add a position to my header in opencart i would like to put a banner in there ok. so here is what i have done so far.
I opened the language file for banner module here /admin/language/english/module/ entered the following code
$_['text_headerbanner'] = 'headerbanner';
Next i opened the banner module admin template at /admin/view/template/module/ and added the following code.
<?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 } ?>
And also added to the javascript section round line 140
html += ' <option value="headerbanner"><?php echo $text_headerbanner; ?></option>';
And then opened the modules controller file here /admin/controller/module/ and entered
$this->data['text_headerbanner'] = $this->language->get('text_headerbanner');
That enabled me to assign a newly created banner to the position "headerbanner" in my admin side.
now i went on to adding the position to the template and i fear this is where all went wonky
so i navigated to /catalog/controller/common/home.php and added
'common/content_middle',
as the second last array item hence the comma at the end. then i created a .php file with the name "headerbanner.php" in /catalog/controller/common/ with the following code in it -
<?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();
}
}
?>
and so i carried on to create the corresponding headerbanner.tpl file for this code in /view/theme/beautyshop/template/common/ with this code in it -
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
And proceeded to call it in my beautyshop header template with -
<?php echo $headerbanner; ?>
And i receive this error
Notice: Undefined variable: headerbanner in /home/demodeto/public_html/catalog/view/theme/beautyshop/template/common/header.tpl on line 702
the code for header.tpl is 1000 lines long but here is the basic snippet of the position being called
?>
<?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>';
}
?>
I Dont know enough about PHP to debug where this code is trying to define the variable any help would be greatly appreciated.
Thank you
Upvotes: 2
Views: 993
Reputation: 16055
The answer is easy: You are missing the child for header
controller:
In catalog/controller/common/header.php
almost at the end find this array:
$this->children = array(
'module/language',
'module/currency',
'module/cart'
);
Now You would have to add Your new child:
$this->children = array(
'module/language',
'module/currency',
'module/cart',
'common/headerbanner'
);
This should do the job.
Upvotes: 2