You may get “Use of undefined constant” error with OpenCart.
Yes, the “Use of undefined constant” error is a code-related issue. We use to get these kinds of tickets frequently, and a common error with OpenCart after a version upgrade or update results in a blank page when accessing the domain.
Example
The customer was getting a blank page after upgrading to a newer version of OpenCart.
In the error log, I found the following errors.
Notice: Use of undefined constant DIR_TEMPLATE - assumed 'DIR_TEMPLATE' in /home/ellex168/public_html/catalog/controller/common/home.php on line 9 Notice: Use of undefined constant DIR_TEMPLATE - assumed 'DIR_TEMPLATE' in /home/ellex168/public_html/catalog/controller/common/column_left.php on line 79 Notice: Use of undefined constant DIR_TEMPLATE - assumed 'DIR_TEMPLATE' in /home/ellex168/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 92 Notice: Use of undefined constant DIR_TEMPLATE - assumed 'DIR_TEMPLATE' in /home/ellex168/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 107 Notice: Error: Could not load template DIR_TEMPLATEdefault/template/common/column_left.tpl! in /home/ellex168/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 107
Causes of error?
As I mentioned earlier, this issue usually happens after updating or upgrading the OpenCart and most probably because of the “vqmod” in OpenCart.
“vQmode” (aka Virtual Quick Mod) is an override system designed to avoid having to change core files. The concept is quite simple. Instead of directly making changes to the core files, the changes are created as xml search/replace script files. These script files are parsed during page load as each “source” core file is loaded with the “include” or “require” php functions. The source is then patched with the script file changes and saved to a temp file. That temp file is then substituted for the original during execution. The original source file is never altered. This results in a “virtual” change to the core during execution without any actual modification to the core files.
So after upgrade or update, the constant value will remain the same, or it will be left blank or removed from the config file and result in the error mentioned above.
How to fix it?
From the error, it is clear that the constant value “DIR_TEMPLATE” is defined wrong or not defined. So to fix the issue, we need to define this constant in the config file of OpenCart, which is the “config.php” file found in the document root.
If you google, you will get sample config.php files of OpenCart, and you could find that the “DIR_TEMPLATE” constant is defined as below.
define('DIR_TEMPLATE', '/home/user/folder/www.site.com/catalog/view/theme/');
As you can see, the constant value “DIR_TEMPLATE” is used to point to the “theme” directory, which can be found under your OpenCart site’s catalog folder.
Add the above line in the config.php and set the correct path, and that will fix the issue!