Template Manager

Coding / Logic mistake - Template Manager

Coding / Logic mistake

by azpro » Sat Sep 27, 2025 7:35 pm

Hi!

Testing the Template Manager gave me an Internal Server error 500. If you activate / switch a template eg override the file templates/override/includes/template.php is missing the extends part of class...

Code: Select all

class override_template extends default_template { 
On line 252 of admin/templates.php we have:

Code: Select all


                // Make sure it doesn't try to extend default_template
                if (strpos($template_content, 'class ' . $expected_class . ' extends default_template') !== false) {
                    $template_content = str_replace(
                        'class ' . $expected_class . ' extends default_template',
                        'class ' . $expected_class,
                        $template_content
                    );
                    file_put_contents($template_php_file, $template_content);
                    error_log("Removed extends default_template from class definition");
                }

the str_replace should not be there IMHO. I commented-out this bit and now it works as expected.

Tnx! Arjan
azpro
Contributor
Posts: 177
Joined: Fri Nov 06, 2020 8:25 am
Phoenix Version: v1.1.0.6
Contact:

Re: Coding / Logic mistake

by tessthepup » Sun Sep 28, 2025 9:22 am

Hi Arjan,

Thanks for the input however I have never received that error.

What is the exact 500 error in your error log?
azpro wrote:Hi!

Testing the Template Manager gave me an Internal Server error 500. If you activate / switch a template eg override the file templates/override/includes/template.php is missing the extends part of class...

Code: Select all

class override_template extends default_template { 
On line 252 of admin/templates.php we have:

Code: Select all


                // Make sure it doesn't try to extend default_template
                if (strpos($template_content, 'class ' . $expected_class . ' extends default_template') !== false) {
                    $template_content = str_replace(
                        'class ' . $expected_class . ' extends default_template',
                        'class ' . $expected_class,
                        $template_content
                    );
                    file_put_contents($template_php_file, $template_content);
                    error_log("Removed extends default_template from class definition");
                }

the str_replace should not be there IMHO. I commented-out this bit and now it works as expected.

Tnx! Arjan
User avatar
tessthepup
Certified Developer
Posts: 382
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Contact:

Re: Coding / Logic mistake

by azpro » Sun Sep 28, 2025 8:22 pm

Hi,

I think the problem is in the logic .. I did extensive testing with deleting and adding/creating templates.

What I found is the created template does not acknowledge the fact that newtemplate/includes/template.php must be different from default/includes/template.php.

See the difference between override/includes/template.php:

https://github.com/CE-PhoenixCart/Phoen ... mplate.php

and default/includes/template.php:

https://github.com/CE-PhoenixCart/Phoen ... mplate.php

So it is not only the

Code: Select all

class override_template extends default_template {
bit - but also the rest of the code in newtemplate/includes/template.php that differs.

But - Impressive piece of code!
azpro
Contributor
Posts: 177
Joined: Fri Nov 06, 2020 8:25 am
Phoenix Version: v1.1.0.6
Contact:

Re: Coding / Logic mistake

by azpro » Sun Sep 28, 2025 8:51 pm

I now created a new template named "test". This is working as expected.

Then selected the "test" template (set Active) and refresh the shop and shop gives Internal server error 500.

This is the Error Log:
[Sun Sep 28 22:45:45.869783 2025] [lsapi:error] [pid 1894:tid 140180207920896] [client 2001:XXXXXXXXX] [host www.example.nl]

Backend fatal error: PHP Fatal error: Uncaught Error: Class "default_template" not found in /home/example/domains/example.nl/public_html/includes/system/versioned/1.0.8.4/template.php:146

\nStack trace:
\n#0 /home/example/domains/example.nl/public_html/includes/system/versioned/1.0.8.2/language.php(174): Template->map()
\n#1 /home/example/domains/example.nl/public_html/includes/system/class_index.php(37): language::map_to_translation()
\n#2 /home/example/domains/example.nl/public_html/includes/system/versioned/1.0.8.4/template.php(146): class_index->autoload()
\n#3 /home/example/domains/example.nl/public_html/includes/system/versioned/1.0.8.2/language.php(174): Template->map()
\n#4 /home/example/domains/example.nl/public_html/includes/system/class_index.php(37): language::map_to_translation()
\n#5 /home/example/domains/example.nl/public_html/includes/classes/magic/loader.php(16): class_index->autoload()
\n#6 /home/example/domains/example.nl/public_html/includes/system/versioned/1.0.8.1/hooks.php(160): Loader->__call()
\n#7 /home/example/domains/example.nl/public_html/includes/application_top.php(27): hooks->generate()
\n#8 /home/example/domains/example.nl/public_html/index.php(13): require('/home/exampl...')
\n#9 {main}\n thrown in /home/example/domains/example.nl/public_html/includes/system/versioned/1.0.8.4/template.php on line 146\n, referer: https://www.example.nl/index.php
After selecting my own template - the shop is running fine!
azpro
Contributor
Posts: 177
Joined: Fri Nov 06, 2020 8:25 am
Phoenix Version: v1.1.0.6
Contact:

Re: Coding / Logic mistake

by azpro » Mon Oct 06, 2025 3:02 pm

@tessthepup

Hi Mark,

Did you have time to check / test?

Just to help others - because I don't want this extremely helpful Add-on to be left in the woods beacuse I made these remaks 8-)

A
azpro
Contributor
Posts: 177
Joined: Fri Nov 06, 2020 8:25 am
Phoenix Version: v1.1.0.6
Contact:

Re: Coding / Logic mistake

by tessthepup » Wed Oct 15, 2025 5:24 pm

azpro wrote:@tessthepup

Hi Mark,

Did you have time to check / test?

Just to help others - because I don't want this extremely helpful Add-on to be left in the woods beacuse I made these remaks 8-)

A
Hi Arjan, sorry work life gets in the way. I have uploaded version 2 which hopefully has sorted the issues.

Please have a test and let me know your thoughts.

Mark
User avatar
tessthepup
Certified Developer
Posts: 382
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Contact: