Common OpenCart Errors issues and How to Solve Them

This Opencart tutorial collects the most common errors that we face while developing and provides solutions for errors, try them and hope you could solve the issues

Cannot delete the admin folder in Opencart 4

https://forum.opencart.com/viewtopic.php?t=228495&p=843586 This solution looks working, for now, change the following lines of code at admin/controller/common/security.php

foreach (glob(trim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {

to following

foreach (glob($next . '/{*,.[!.]*,..?*}', GLOB_MARK|GLOB_BRACE) as $file) {

2. Blank White Pages or 500 Internal Server Error

Blank white pages are a PHP error that for some reason the error messages don’t show because your server is not set up to display the errors.

  1. Go to the admin>> System >> Setting >> Edit store >> Server tab and at the end where you see the Error handling choose Yes to “Display Errors “.
  2. If you still don’t see the error, open php.ini and add code below: display_errors = 1; error_reporting = E_ALL; log_errors = 1;
  3. If you still don’t see the error then open index.php and add code below at the top (line 2): ini_set(‘display_errors’, 1); ini_set(‘log_errors’, 1); error_reporting(E_ALL);
  4. Still seeing the error then, set your “Output Compression Level” to 0 in the System > Settings > Server tab.
  5. If you still see the error, solve the issues but if you did not see the errors then most probably it will be a Server error.
  6. You can see error logs in the file also if you had enabled it.
    Blank screen issues in Opencart

Above mostly it gets solved and the 500 Internal Server Error can be solved with a similar approach.

2. Undefined Index / Variable

An undefined variable in the source code of a computer program is a variable that is accessed in the code but has not been previously declared by that code. So for that using “isset()” to check if the variable has been set will solve the issue.

Error variant:

Notice: Undefined index: filter in /Applications/XAMPP/xamppfiles/htdocs/opencart303/catalog/controller/product/category.php on lin

Solution
//$filter = $this->request->get['filter'];

if (isset($this->request->get['filter'])) {
    $filter = $this->request->get['filter'];
} else {
    $filter = '';
}
  • Commenting $filter = $this->request->get[‘filter’]; and checking with isset is one way to solve it.
  • If you get the issue while installing the modules or extensions then you need to check the code or solve the issues or contacting the developer can be also another solution.

3. Undefined Function / Method

Undefined function/method errors are seen when you call those functions or methods that are not defined and not found. IE_ERROR: A fatal error that causes script termination “Fatal error: Call to undefined function” or “Fatal error: Call to undefined method”. It happens if files are not found or the extensions are not compatible with your OpenCart version. Solutions can be below:

Error variant:

Related to OpenCart core files

  • Fatal error: Uncaught Error: Call to undefined method DB\MySQLi::query()
  • Fatal error: Uncaught Error: Call to undefined method Cart\Cart::getProducts() 
  • Fatal error: Uncaught Error: Call to undefined method ControllerAccountLogin::validate() in …/catalog/controller/account/login.php:54 

Go to the file and check whether the function or methods are defined there.

4. Headers Already Sent

Error variant:
  • Warning: Cannot modify header information – headers already sent by (output started at /public_html/config.php:31) in /path/public_html/index.php online.
Solution:

Remove spaces at the beginning and end of the file mentioned. Like in the above error check with the config.php

5. Session Issue

  1. The product on the cart is self-cleared.
  2. The product on the cart is cleared after the user logged in.
  3. No items stored at product compares.
  4. OpenCart admin always asking to login and get message “Invalid token session. Please log in again”.
Error variant:
  • Warning: session_start () [function.session-start]: open (/tmp/…, O_RDWR) failed: No such file or directory (2) in /path/public_html/system /library /session.php on line
Solution:

No such file or directory issue

  1. Open php.ini and add code below:session.save_path = /tmp;
  2. If the solution above does not work, contact your host and ask them how to set session.save_path.

6. Allowed Memory Size Exhausted

This error happens because your memory is not enough to execute the PHP code (uploading large images, deleting a lot of products, sending mass emails, etc). Increasing the memory allocated for PHP will solve the issue.

Error variant:
  • Fatal error: the Allowed memory size of 1111 bytes exhausted (tried to allocate 1111 bytes) in /path/public_html/system/library/image.php on line
Solution:
  1. Edit php.ini and set memory_limit = 128M;
  2. Or put code below to .htaccess php_value memory_limit 128M
  3. If the above does not works then contacting the hosting providers is only the solution where they can increase the number.

Warning: Use of undefined constant DIR_STORAGE – assumed ‘DIR_STORAGE’ (this will throw an Error in a future version of PHP) in …/config.php on line

Some other errors that you can face are below:

Error: Calls to magic methods are not allowed!

// Stop any magical methods being called
if (substr($this->method, 0, 2) == '__') {
return new \Exception('Error: Calls to magic methods are not allowed!');
}

Error: Could not call product/category

// Initialize the class
		if (is_file($file)) {
			include_once($file);
		
			$controller = new $class($registry);
		} else {
			return new \Exception('Error: Could not call ' . $this->route . '/' . $this->method . '!');
		}

Error: Could not load model

if (!$this->registry->has('model_' . str_replace('/', '_', $route))) {
    $file = DIR_APPLICATION . 'model/' . $route . '.php';
    $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $route);

    if (is_file($file)) {
        include_once($file);
        $proxy = new Proxy();
	// Overriding models is a little harder so we have to use 
        //  PHP's magic methods
	// In future version we can use runkit
        foreach (get_class_methods($class) as $method) {
            $proxy->{$method} = $this->callback($this->registry, $route . '/' . $method);
        }

        $this->registry->set('model_' . str_replace('/', '_', (string)$route), $proxy);
    } else {
        throw new \Exception('Error: Could not load model ' . $route . '!');
    }
}

Error: Could not load library

Error: Could not load helper

Error: Could not load cache adaptor Memcache/Redis/APC cache!

$class = 'Cache\\' . $adaptor;
if (class_exists($class)) {
    $this->adaptor = new $class($expire);
} else {
    throw new \Exception('Error: Could not load cache adaptor ' . $adaptor . ' cache!');
}

Error: Could not load database adaptor mpdo/mssql/mysql/mysqli/postgre !

$class = 'DB\\' . $adaptor;
if (class_exists($class)) {
    $this->adaptor = new $class($hostname, $username, $password, $database, $port);
} else {
    throw new \Exception('Error: Could not load database adaptor ' . $adaptor . '!');
}

Error: Could not make a database connection using this username and password

Error: Could not connect to database opencart

Error: PHP GD is not installed!

if (!extension_loaded('gd')) {
    exit('Error: PHP GD is not installed!');
}

Error: Could not load image filename!

Error: Invalid session ID!

Warning: Install folder still exists and should be deleted for security reasons!

Installed bad extension, pressed refresh in the modification, and both admin panel and site are down

Remove it from the database, then open config.php and find what is the value defined for storage. Go to that storage/ folder, then go to modification and remove folders, similarly go to upload/ folder and see if there are folders if you have, remove it also. With this, it will remove the cached files and folder. Then, you can access your admin again.

Fatal error uncaught exception

Fatal error: Uncaught Exception: Error: Table ‘….oc_session’ doesn’t exist in engine<br />Error No: 1932<br />SELECT `data` FROM `oc_session` WHERE session_id = ‘….’ AND expire > 1548638620 in …/system/library/db/mysqli.php:40 Stack trace: #0 …/system/library/db.php(45): DB\MySQLi->query(‘SELECT `data` F…’) #1 

For these errors to solve creating a database table will solve most of the issues

Fatal error: Uncaught Exception: Error: Could not load database adaptor DB_DRIVER!

Check in the system/library/DB folder whether the required driver file is there.

https://webocreation.com/twig-cache-removing-while-developing-theme-or-module-developer-tips/

Hope you solve the problems, if you find them please let us know, then we try to provide the solutions.

Opencart error, Opencart blank white page, Opencart headers already sent, opencart undefined index, opencart undefined variable, opencart restriction in effect, opencart memory size exhausted, opencart undefined method, opencart undefined function, opencart invalid token session, opencart internal server error, Vqmod, opencart out of memory

Previous articleHow to add HTML, google analytics, tag manager, third party JS code in Opencart
Next articleCategories management in Opencart 4
Author of three Opencart book. The recent Opencart 4 book is at https://amzn.to/4dOlbOR

4 COMMENTS

  1. I am using Opencart 3.0.6 Journal theme V3.

    Problem1:
    When a registered customer goes to the payment page after adding a product to their cart, they automatically log out and switch to guest user mode. For this reason, he cannot see the products in his cart.

    Problem2
    When the admin user changes a setting in the administration panel and clicks the “Save” button, it logs out and asks me to log in again. This issue is not a regular issue. Sometimes it happens in different processes.

    If there is a known solution to these problems I would greatly appreciate it.

    Thanks.

LEAVE A REPLY

Please enter your comment!
Please enter your name here