Post by MikeChipshop » Thu Feb 04, 2016 7:27 pm

Morning all!

I'm trying to add a new position in the header, and it seems to have changed since the ol' Version 1.x days, so i wondered if i could get a little help here, or pointed in the right direction.
I've searched Google and the forums here to no avail, all i keep coming up with is version 1.x answers.

In my header.tpl file for my theme, i have a sidebar that sits to the left, this sidebar is global across the whole site and contains a navigation and i'm looking to have it contain two positions for modules to be placed.

I've added the normal gubbins as per v1 to the controller files, template files as per this article http://www.opencartnews.com/tutorials/a ... positions/

The issue comes when i get to the section they've titled "Linking it all up" where you're supposed to find...

Code: Select all

$this->render();
and add after...

Code: Select all

$this->children = array(
   'common/content_footer'
);
The issue i'm having is that the original piece of code either no longer exists in v2, or never existed in the header controller in the first place.

Any idea on how to go about creating a new position in the header for a v2 OC site?

Just FYI, i'm not looking to do this with an extension free or paid for, as i want to learn how it's done.

Many thanks,


Mike

New member

Posts

Joined
Mon Oct 21, 2013 5:17 pm

Post by ocart777 » Thu Feb 04, 2016 9:22 pm

header.php controller

Code: Select all

$this->children = array(
   'common/content_header'
);
now it should be

Code: Select all

$data['content_header'] = $this->load->controller('common/content_header');
and once you call the content_header from header.tpl it will load the content_header.php from controller which will grab a view from content_header.tpl

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by MikeChipshop » Thu Feb 04, 2016 9:48 pm

Thanks for that ocart777,

I actually tried that earlier by placing...

Code: Select all

	
$data['sidebar_one'] = $this->load->controller('common/sidebar_one');	
$data['sidebar_two'] = $this->load->controller('common/sidebar_two');
...after...

Code: Select all

$data['cart'] = $this->load->controller('common/cart');
However this then bring the error...
Notice: Error: Could not load model pathtosite/catalog/model/setting/extension.php! in pathtosite/vqmod/vqcache/vq2-system_storage_modification_system_engine_loader.php on line 63
Any ideas? Maybe i'm putting them in the wrong place?

New member

Posts

Joined
Mon Oct 21, 2013 5:17 pm

Post by ocart777 » Thu Feb 04, 2016 10:21 pm

on your sidebar_one and/or sidebar_two controller file there you're trying to load a model file which has been move to other directory in OC2. open your sidebar_one and/or sidebar_two controller file and search for

Code: Select all

$this->load->model('setting/extension')
replace with

Code: Select all

$this->load->model('extension/extension')

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by MikeChipshop » Thu Feb 04, 2016 10:52 pm

Thanks again, still no joy though.

Getting a...
Notice: Undefined variable: sidebar_one in var/www/vhosts/44/444967/webspace/httpdocs/website.com/catalog/view/theme/pharmaplus/template/common/header.tpl on line 56
...error now.

New member

Posts

Joined
Mon Oct 21, 2013 5:17 pm

Post by MikeChipshop » Thu Feb 04, 2016 10:59 pm

For Clarity i'll concentrate on getting one new position in rather than both, so i currently have...

catalog/view/theme/mytheme/template/common/header.tpl

Code: Select all

<?php echo $sidebar_one; ?>
catalog/controller/common/header.php

Code: Select all

$data['language'] = $this->load->controller('common/language');
$data['currency'] = $this->load->controller('common/currency');
$data['search'] = $this->load->controller('common/search');
$data['cart'] = $this->load->controller('common/cart');	
$data['sidebar_one'] = $this->load->controller('common/sidebar_one');	
$data['sidebar_two'] = $this->load->controller('common/sidebar_two');	
catalog/controller/common/sidebar_one.php

Code: Select all

<?php
class ControllerCommonSidebarOne 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 = (string)$this->request->get['route'];
        } else {
            $route = 'common/home';
        }
 
        $layout_id = 0;
 
        if ($route == 'product/category' && isset($this->request->get['path'])) {
            $path = explode('_', (string)$this->request->get['path']);
 
            $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
        }
 
        if ($route == 'product/product' && isset($this->request->get['product_id'])) {
            $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
        }
 
        if ($route == '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('extension/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'] == 'sidebar_one' && $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/sidebar_one.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/common/sidebar_one.tpl';
        } else {
            $this->template = 'default/template/common/sidebar_one.tpl';
        }
 
        $this->render();
    }
}
?>
I also of course have the section added to the admin area to allow for the selection in the drop down, but i don't think that's got anything to do with it.

Many thanks for any help.

New member

Posts

Joined
Mon Oct 21, 2013 5:17 pm

Post by Qphoria » Thu Feb 04, 2016 11:09 pm

MikeChipshop wrote:Thanks again, still no joy though.

Getting a...
Notice: Undefined variable: sidebar_one in var/www/vhosts/44/444967/webspace/httpdocs/website.com/catalog/view/theme/pharmaplus/template/common/header.tpl on line 56
...error now.
Actually when someone gives you a tip and it fixes the error in question... that is considered "joy".
You may have new errors but that is progression. Saying there is no joy when the issue reported was fixed is counter productive.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Thu Feb 04, 2016 11:13 pm

Based on your post that should work fine.
Be sure you are saving all the files to the correct place and not saving a local copy while testing remotely or something

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by MikeChipshop » Thu Feb 04, 2016 11:30 pm

Qphoria wrote: Actually when someone gives you a tip and it fixes the error in question... that is considered "joy".
You may have new errors but that is progression. Saying there is no joy when the issue reported was fixed is counter productive.
OK, for clarification, "No joy" on the original issue but ocart777's help is extremely appreciated on the issue.

I'll take stock of your second point though, all files are correctly been edited and uploaded, to prove this to myself, i grabbed the live files and looked at them and they do indeed have all the edits as per my post.

Does OpenCart cache these files anywhere they may be loading an older version? Some where that may need clearing perhaps?

New member

Posts

Joined
Mon Oct 21, 2013 5:17 pm

Post by ocart777 » Fri Feb 05, 2016 1:30 am

from the look of your code it should be good but please try to replace the content of sidebar_one.php controller file with this

Code: Select all

<?php
class ControllerCommonSidebarOne extends Controller {
	public function index() {
		$this->load->model('design/layout');

		if (isset($this->request->get['route'])) {
			$route = (string)$this->request->get['route'];
		} else {
			$route = 'common/home';
		}
 
		$layout_id = 0;

		if ($route == 'product/category' && isset($this->request->get['path'])) {
			$this->load->model('catalog/category');

			$path = explode('_', (string)$this->request->get['path']);

			$layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
		}

		if ($route == 'product/product' && isset($this->request->get['product_id'])) {
			$this->load->model('catalog/product');

			$layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
		}

		if ($route == 'information/information' && isset($this->request->get['information_id'])) {
			$this->load->model('catalog/information');

			$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');
		}
 
		$this->load->model('extension/module');

		$data['modules'] = array();

		$modules = $this->model_design_layout->getLayoutModules($layout_id, 'sidebar_one');

		foreach ($modules as $module) {
			$part = explode('.', $module['code']);

			if (isset($part[0]) && $this->config->get($part[0] . '_status')) {
				$data['modules'][] = $this->load->controller('module/' . $part[0]);
			}

			if (isset($part[1])) {
				$setting_info = $this->model_extension_module->getModule($part[1]);

				if ($setting_info && $setting_info['status']) {
					$data['modules'][] = $this->load->controller('module/' . $part[0], $setting_info);
				}
			}
		}

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/sidebar_one.tpl')) {
			return $this->load->view($this->config->get('config_template') . '/template/common/sidebar_one.tpl', $data);
		} else {
			return $this->load->view('default/template/common/sidebar_one.tpl', $data);
		}
    }
}

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by Qphoria » Fri Feb 05, 2016 2:45 am

Well just based on the controller to view relationship
if your controller has
$data['xxx'] = 'yyy';

and your tpl has
<?php echo $xxx; ?>

that should work.

Since it throws an error I'd only guess it isn't loading.
If you have some ocmods you need to hit refresh manually in the extensions->modifications page

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by viethemes » Sat Feb 06, 2016 11:07 pm

Or you can try to use my free extension Extra Positions :)

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm


Post by theme » Tue Mar 15, 2016 8:05 pm

opencart version 2.2.0.0
$this->request->get['route']; is giving error in .tpl file
Notice: Undefined property: Template\BasicOverride::$request /template/common/column_right.tpl

Newbie

Posts

Joined
Thu Mar 10, 2016 5:23 pm
Who is online

Users browsing this forum: No registered users and 15 guests