Page 1 of 1

[Solved]Fatal error: Call to a member function getUserName()

Posted: Fri Apr 01, 2016 10:10 am
by nikhanz
Hello,

I'm new here and also just enter opencart world. Currently, i just done importing opencart file from hosting to localhost. Seem like have error notice

Code: Select all

Fatal error: Call to a member function getUserName() on null in C:\xampp\htdocs\tmt1\admin\controller\common\header.php on line 41
header.php

Code: Select all

<?php
class ControllerCommonHeader extends Controller {
	public function index() {
		$data['title'] = $this->document->getTitle();

		if ($this->request->server['HTTPS']) {
			$data['base'] = HTTPS_SERVER;
		} else {
			$data['base'] = HTTP_SERVER;
		}

		$data['description'] = $this->document->getDescription();
		$data['keywords'] = $this->document->getKeywords();
		$data['links'] = $this->document->getLinks();
		$data['styles'] = $this->document->getStyles();
		$data['scripts'] = $this->document->getScripts();
		$data['lang'] = $this->language->get('code');
		$data['direction'] = $this->language->get('direction');

		$this->load->language('common/header');

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

		$data['text_order'] = $this->language->get('text_order');
		$data['text_order_status'] = $this->language->get('text_order_status');
		$data['text_complete_status'] = $this->language->get('text_complete_status');
		$data['text_return'] = $this->language->get('text_return');
		$data['text_customer'] = $this->language->get('text_customer');
		$data['text_online'] = $this->language->get('text_online');
		$data['text_approval'] = $this->language->get('text_approval');
		$data['text_product'] = $this->language->get('text_product');
		$data['text_stock'] = $this->language->get('text_stock');
		$data['text_review'] = $this->language->get('text_review');
		$data['text_affiliate'] = $this->language->get('text_affiliate');
		$data['text_store'] = $this->language->get('text_store');
		$data['text_front'] = $this->language->get('text_front');
		$data['text_help'] = $this->language->get('text_help');
		$data['text_homepage'] = $this->language->get('text_homepage');
		$data['text_documentation'] = $this->language->get('text_documentation');
		$data['text_support'] = $this->language->get('text_support');
		$data['text_logged'] = sprintf($this->language->get('text_logged'), $this->user->getUserName());
		$data['text_logout'] = $this->language->get('text_logout');

		if (!isset($this->request->get['token']) || !isset($this->session->data['token']) || ($this->request->get['token'] != $this->session->data['token'])) {
			$data['logged'] = '';

			$data['home'] = $this->url->link('common/dashboard', '', 'SSL');
		} else {
			$data['logged'] = true;

			$data['home'] = $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL');
			$data['logout'] = $this->url->link('common/logout', 'token=' . $this->session->data['token'], 'SSL');

			// Orders
			$this->load->model('sale/order');

			// Processing Orders
			$data['order_status_total'] = $this->model_sale_order->getTotalOrders(array('filter_order_status' => implode(',', $this->config->get('config_processing_status'))));
			$data['order_status'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&filter_order_status=' . implode(',', $this->config->get('config_processing_status')), 'SSL');

			// Complete Orders
			$data['complete_status_total'] = $this->model_sale_order->getTotalOrders(array('filter_order_status' => implode(',', $this->config->get('config_complete_status'))));
			$data['complete_status'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&filter_order_status=' . implode(',', $this->config->get('config_complete_status')), 'SSL');

			// Returns
			$this->load->model('sale/return');

			$return_total = $this->model_sale_return->getTotalReturns(array('filter_return_status_id' => $this->config->get('config_return_status_id')));

			$data['return_total'] = $return_total;

			$data['return'] = $this->url->link('sale/return', 'token=' . $this->session->data['token'], 'SSL');

			// Customers
			$this->load->model('report/customer');

			$data['online_total'] = $this->model_report_customer->getTotalCustomersOnline();

			$data['online'] = $this->url->link('report/customer_online', 'token=' . $this->session->data['token'], 'SSL');

			$this->load->model('sale/customer');

			$customer_total = $this->model_sale_customer->getTotalCustomers(array('filter_approved' => false));

			$data['customer_total'] = $customer_total;
			$data['customer_approval'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . '&filter_approved=0', 'SSL');

			// Products
			$this->load->model('catalog/product');

			$product_total = $this->model_catalog_product->getTotalProducts(array('filter_quantity' => 0));

			$data['product_total'] = $product_total;

			$data['product'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&filter_quantity=0', 'SSL');

			// Reviews
			$this->load->model('catalog/review');

			$review_total = $this->model_catalog_review->getTotalReviews(array('filter_status' => false));

			$data['review_total'] = $review_total;

			$data['review'] = $this->url->link('catalog/review', 'token=' . $this->session->data['token'] . '&filter_status=0', 'SSL');

			// Affliate
			$this->load->model('marketing/affiliate');

			$affiliate_total = $this->model_marketing_affiliate->getTotalAffiliates(array('filter_approved' => false));

			$data['affiliate_total'] = $affiliate_total;
			$data['affiliate_approval'] = $this->url->link('marketing/affiliate', 'token=' . $this->session->data['token'] . '&filter_approved=1', 'SSL');

			$data['alerts'] = $customer_total + $product_total + $review_total + $return_total + $affiliate_total;

			// Online Stores
			$data['stores'] = array();

			$data['stores'][] = array(
				'name' => $this->config->get('config_name'),
				'href' => HTTP_CATALOG
			);

			$this->load->model('setting/store');

			$results = $this->model_setting_store->getStores();

			foreach ($results as $result) {
				$data['stores'][] = array(
					'name' => $result['name'],
					'href' => $result['url']
				);
			}
		}

		return $this->load->view('common/header.tpl', $data);
	}
}

Re: Error: Fatal error: Call to a member function getUserNam

Posted: Sat Apr 02, 2016 4:24 am
by Randem
Hi nikhanz,

When asking for help it would help to give as much information as possible.

What version of OpenCart?
What you were doing at the time of the error?
Do you have MODS installed?
What is the code on line 41?
Importing from host to local host???
ETC...

There will be a lot of guessing here and very little help if no one want to do all the leg work just to find out what you mean.

Re: Error: Fatal error: Call to a member function getUserNam

Posted: Mon Apr 04, 2016 11:19 am
by nikhanz
Randem wrote:Hi nikhanz,

When asking for help it would help to give as much information as possible.

What version of OpenCart?
What you were doing at the time of the error?
Do you have MODS installed?
What is the code on line 41?
Importing from host to local host???
ETC...

There will be a lot of guessing here and very little help if no one want to do all the leg work just to find out what you mean.
Hi Randem,

I apologise, here the information:

Opencart Version 2.0.3.1
Just handover this opencart, previously other developer built it
I'm not sure about MODS, you mean extension? VQMOD is installed anyway.
Code on line 41 is:

Code: Select all

$data['text_logged'] = sprintf($this->language->get('text_logged'), $this->user->getUserName());
Yes, this site originally from live site and this site work. I decide to duplicate for test use, from hosting to local PC, doing everything import and export database, including website file & folder. After done, the error was appear.

I have make two duplicate 1 at local PC and more on same hosting, on hosting admin dashboard can be access but front end appear this error, but different:

Code: Select all

Fatal error: Call to a member function getUserName() on a non-object in /home/admin/domains/anydomain.my/public_html/onlinestore_beta/admin/controller/common/header.php on line 41

Re: Error: Fatal error: Call to a member function getUserNam

Posted: Mon Apr 04, 2016 4:33 pm
by Randem

Re: Error: Fatal error: Call to a member function getUserNam

Posted: Thu Aug 04, 2016 10:20 am
by nikhanz

Re: Error: Fatal error: Call to a member function getUserNam

Posted: Thu Aug 04, 2016 10:25 am
by Randem
You are welcome. Glad they helped!

Re: [Solved]Fatal error: Call to a member function getUserNa

Posted: Thu Nov 10, 2016 2:25 am
by unigira
Hello,

I have the same issue.
Could you please provide the updated link or the title of the thread. Your link doesn't seem to work anymore..
Thanks

Re: [Solved]Fatal error: Call to a member function getUserNa

Posted: Mon Nov 21, 2016 10:24 am
by Randem