Page 1 of 2

[SOLVED] Twig error / blank product edit page

Posted: Thu Jan 14, 2021 11:46 pm
by siteadvice
I have been trying to solve a problem with my development server and I'm completely stuck, so I hope someone in the community has some advice for me.

My live, public site works fine. However, when using my duplicate development site and trying to open a product edit page in the Opencart dashboard I get a blank white screen.

The error from the error_log file is pasted below (path names removed for privacy and to make it easier to read).

The development server is a very similar spec to the live server and both sites are using the same version of PHP. The version of Opencart is the same as the live site (3.0.3.2) and the development database is a recent backup from the live server.

I have tried restoring the whole system/library/template folder from the original Opencart 3.0.3.2 repository, just in case, but that didn't help. I didn't really think it would, but it was worth a try!

The obvious culprit would be one of the extensions, but I have tried disabling every extension that is not built in to Opencart and it doesn't make any difference.

Any ideas anybody!?

PHP Fatal error: Uncaught Error: Call to a member function needsEnvironment() on bool in /home/{{path}}/system/library/template/Twig/Node/Expression/Function.php:26
Stack trace:
#0 /home/{{path}}/system/library/template/Twig/Compiler.php(97): Twig_Node_Expression_Function->compile(Object(Twig_Compiler))
#1 /home/{{path}}/system/library/template/Twig/Node/Print.php(30): Twig_Compiler->subcompile(Object(Twig_Node_Expression_Function))
#2 /home/{{path}}/system/library/template/Twig/Node.php(110): Twig_Node_Print->compile(Object(Twig_Compiler))
#3 /home/{{path}}/system/library/template/Twig/Node.php(110): Twig_Node->compile(Object(Twig_Compiler))
#4 /home/{{path}}/system/library/template/Twig/Compiler.php(97): Twig_Node->compile(Object(Twig_Compiler))
#5 /home/{{path}}/system/library/template/Twig/Node/Module.php(277): Twig_Compiler->subcompile(Object(Twig_N in /home/{{path}}/system/library/template/Twig/Node/Expression/Function.php on line 26

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 12:18 am
by JNeuhoff
Make sure you use the same PHP version on your local server that is used on the live site.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 12:47 am
by mikeinterserv
siteadvice wrote:
Thu Jan 14, 2021 11:46 pm
both sites are using the same version of PHP.
They ARE

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 12:54 am
by siteadvice
Thanks @JNeuhoff - that is good thinking, but as @mikeinterserv says, I already confirmed that both installations are running the same version of PHP. For the record it is ea-php72. Out of interest, I tried upgrading to 7.4, just to see if I got a different/more helpful error, but it doesn't make any difference.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 1:00 am
by JNeuhoff
You may also want to clear and then refresh your OCmod and VQmod modification caches. And then check the OCmod log for any errors.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 1:05 am
by mikeinterserv
Whats on line 26 of your Function.php

Maybe you call a local variable that is global

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 1:15 am
by siteadvice
@JNeuhoff Thanks, but I have tried that. I don't have VQMOD installed anyway.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 1:17 am
by siteadvice
@mikeinterserv It is just the regular line from the core Opencart/Twig code, which happens to be:
$this->setAttribute('needs_environment', $function->needsEnvironment());
I don't know what that does, to be honest.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 1:34 am
by mikeinterserv
Well its NOT in my opencart twig code
You have a very different path in your system folder

appears something like the environment loader is not working for the function
I will struggle to help from here as I do not have the same files etc as you

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 1:44 am
by JNeuhoff
The error indicates that the Twig environment is missing. Make sure the system/library/template/twig.php is not corrupted nor modified.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 1:52 am
by siteadvice
@mikeinterserv You do not have this folder...?
/system/library/template/Twig/Node/Expression
I assure you it is part of the Opencart distributable.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 1:56 am
by mikeinterserv
No not at all -
I have
/htdocs/Shop/system/library/template

and inside just 2 files
template.php
twig.php

You have EXTENDED Twig
Either deliberately because you need that or NOT I don't know
I do know that is NOT the CORE STANDARD install.

Your function is failing because the environment is not loaded

Maybe see if you can find this code SOMEWHERE :-)

Code: Select all

$twig = new \Twig\Environment($loader);
$function = new \Twig\TwigFunction('function_name', function () {
    // ...
});
$twig->addFunction($function);

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 2:44 am
by straightlight
siteadvice wrote:
Fri Jan 15, 2021 1:52 am
@mikeinterserv You do not have this folder...?
/system/library/template/Twig/Node/Expression
I assure you it is part of the Opencart distributable.
However, it is not what is being delivered from Opencart.com which are the distributions that this site officially supports. It is confirmed that the TWIG sub-folder is not included in the system/library/template folder. Only two files are officially distributed. Which means, you are using a development version of Opencart which also leads to why you may encounter additional errors from those distributions.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 2:47 am
by sw!tch
You cant compare 3.0.3.6 version to 3.0.3.2, there were significant updates to twig in 3.0.3.6.

If on a version below 3.0.3.6 ensure you are on PHP 7.3.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 2:48 am
by straightlight
In addition to the above, the master branch also contains an updated bootstrap and TWIG Engine as part of the recent development core.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 2:51 am
by mikeinterserv
Yep start with this ^
as straighlight suggets

OR

Do a new install :-)

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 3:31 am
by by mona
Whilst what straightlight says is true, you should stick to the official downloads.
However to clear something up ... see attached the official download - because I do have that folder

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 3:38 am
by mikeinterserv
I'm trying to see what's in another 3.0.3.2 I have
But vm instances will NOT start on europe-west2 on google cloud
If I have that file structure there I can help you more.

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 3:49 am
by sw!tch
As mentioned before there are significant updates to twig in 3.0.3.6. Twig was updated and pulled in via composer, along with other updates.

You shouldn't be comparing 3.0.3.6 to 3.0.3.2.
https://github.com/opencart/opencart/tr ... y/template

Re: Twig error / blank product edit page

Posted: Fri Jan 15, 2021 5:55 pm
by paulfeakins
siteadvice wrote:
Thu Jan 14, 2021 11:46 pm
My live, public site works fine. However, when using my duplicate development site and trying to open a product edit page in the Opencart dashboard I get a blank white screen.
Take a fresh copy of it on to dev and see if the issue still occurs.