Twig fix

After version released on July 18, 2020 modifications of the existing twig templates were not possible, and this resulted on multiple requests from customers that my extensions are not installed in the latest version of the shop.

Finally I got some time to investigate what was the problem there.

You see, Opencart uses twig, but it uses it's own ocmod file called modifications.xml in system which adds
the path where templates are located. In that modification it adds the additional template paths such as
system/storage/modification/ which would load the files modified with ocmod changes.

Without further complications here is the problem:

The modification.xml it searches for the string

$loader = new \Twig_Loader_Filesystem(DIR_TEMPLATE);

The problem is that this line doesn't exist in the original twig.php file and therefore
this file is not modified, as a result, the necessary modification is not done.

Further more this class \Twig_Loader_Filesystem is already deprecated as it's visible in it's source code.

That's why the modification should be the following:

It should search for:
$loader = new \Twig\Loader\ArrayLoader(array($filename . '.twig' => $code));

And then it should replace it with

$loader = new \Twig\Loader\FilesystemLoader();
if (defined('DIR_CATALOG') && is_dir(DIR_MODIFICATION . 'admin/view/template/')) {
$loader->addPath(DIR_MODIFICATION . 'admin/view/template/');
} elseif (is_dir(DIR_MODIFICATION . 'catalog/view/theme/')) {
$loader->addPath(DIR_MODIFICATION . 'catalog/view/theme/');

Until it's sorted in the official release, I've done small free extension which would fix the problem
and will allow your extensions to work the same as before. Which you can find here. Feel free to use it.

Hope that helps

Nik Chankov
Nik Chankov
a.k.a. nchankov

Nik started creating opencart extensions since 2011. And has more than 20 years experience in Software development.