Post by samdz » Tue Jan 09, 2024 5:08 am

JNeuhoff wrote:
Tue Jan 09, 2024 2:33 am
It's a similar logic for OpenCart 4:

Code: Select all

	// event handler for admin/view/catalog/product_form/before
	public function eventViewCatalogProductFormBefore( string &$route, array &$data, string &$template_code ): void {
		// ....
		$code = $this->getTemplateCode($route,$code);
		// .... modify $code
		$template_code = $code;
	}

	protected function getTemplateCode( $route, &$code ) {
		if (!empty($code)) {
			return $code;
		}

		$file = DIR_TEMPLATE . $route . '.twig';
		if (is_file($file)) {
			$code = file_get_contents( $file );
		} else {
			trigger_error("Cannot find template file for route '$route'");
			exit;
		}

		return $code;
	}
Thank you for your reply,

I have tested the code but I got error:

Code: Select all

Notice: Cannot find template file for route 'extension/opencart/dashboard/recent_info'
Note I want to edit the this file:

Code: Select all

admin/view/extension/opencart/dashboard/recent_info.twig
Any help!

Active Member

Posts

Joined
Fri Jan 28, 2011 3:02 am

User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by samdz » Tue Jan 09, 2024 10:42 pm

JNeuhoff wrote:
Tue Jan 09, 2024 6:20 pm
What's in your DIR_TEMPLATE?
I am using on localhost (wampserver);
it's on config file like this:

Code: Select all

define('DIR_TEMPLATE', DIR_APPLICATION . 'view/template/');
I am tring to add CUSTOMER ID column to recent module (latest orders) in the dashboard page.

Active Member

Posts

Joined
Fri Jan 28, 2011 3:02 am

User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by samdz » Wed Jan 10, 2024 12:25 am

JNeuhoff wrote:
Tue Jan 09, 2024 11:05 pm
So what's in your DIR_APPLICATION then?
this is my admin config file:

Code: Select all

<?php
// APPLICATION
define('APPLICATION', 'Admin');

// HTTP
define('HTTP_SERVER', 'http://localhost/oc4024e/admin21/');
define('HTTP_CATALOG', 'http://localhost/oc4024e/');

// DIR
define('DIR_OPENCART', 'C:/wamp64/www/oc4024e/');
define('DIR_APPLICATION', DIR_OPENCART . 'admin21/');
define('DIR_EXTENSION', DIR_OPENCART . 'extension/');
define('DIR_IMAGE', DIR_OPENCART . 'image/');
define('DIR_SYSTEM', DIR_OPENCART . 'system/');
define('DIR_CATALOG', DIR_OPENCART . 'catalog/');
define('DIR_STORAGE', 'C:/wamp64/storage4024e/');
define('DIR_LANGUAGE', DIR_APPLICATION . 'language/');
define('DIR_TEMPLATE', DIR_APPLICATION . 'view/template/');
define('DIR_CONFIG', DIR_SYSTEM . 'config/');
define('DIR_CACHE', DIR_STORAGE . 'cache/');
define('DIR_DOWNLOAD', DIR_STORAGE . 'download/');
define('DIR_LOGS', DIR_STORAGE . 'logs/');
define('DIR_SESSION', DIR_STORAGE . 'session/');
define('DIR_UPLOAD', DIR_STORAGE . 'upload/');

// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'oc4024e');
define('DB_PASSWORD', '123456');
define('DB_SSL_KEY', '');
define('DB_SSL_CERT', '');
define('DB_SSL_CA', '');
define('DB_DATABASE', 'oc4024e');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');

// OpenCart API
define('OPENCART_SERVER', 'https://www.opencart.com/');

Active Member

Posts

Joined
Fri Jan 28, 2011 3:02 am

Post by JNeuhoff » Wed Jan 10, 2024 1:20 am

So does the file 'C:/wamp64/www/oc4024e/admin21/view/template/extension/opencart/dashboard/recent_info.twig' exist?

Perhaps the code should be:

Code: Select all

	protected function getTemplateCode( $route, &$code ) {
		if (!empty($code)) {
			return $code;
		}

		$file = DIR_EXTENSION.'opencart/admin/view/template/dashboard/recent_info.twig';
		if (is_file($file)) {
			$code = file_get_contents( $file );
		} else {
			trigger_error("Cannot find template file for route '$route'");
			exit;
		}

		return $code;
	}
Your $route looks strange.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by samdz » Thu Jan 11, 2024 5:18 am

JNeuhoff wrote:
Wed Jan 10, 2024 1:20 am
So does the file 'C:/wamp64/www/oc4024e/admin21/view/template/extension/opencart/dashboard/recent_info.twig' exist?

Perhaps the code should be:

Code: Select all

	protected function getTemplateCode( $route, &$code ) {
		if (!empty($code)) {
			return $code;
		}

		$file = DIR_EXTENSION.'opencart/admin/view/template/dashboard/recent_info.twig';
		if (is_file($file)) {
			$code = file_get_contents( $file );
		} else {
			trigger_error("Cannot find template file for route '$route'");
			exit;
		}

		return $code;
	}
Your $route looks strange.
It's working now, thank you so much for your help.
But why it didn't working when use your code and working without your code ??

Active Member

Posts

Joined
Fri Jan 28, 2011 3:02 am

Post by JNeuhoff » Thu Jan 11, 2024 6:15 pm

It's all about the way how the $route is translated into the correct path of the corresponding twig file. OpenCart has a weird way of dealing with extensions :)

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by grgr » Fri Apr 25, 2025 6:20 pm

I've updated the above slightly for 4.1.x, though I have yet to get to the correct path for a theme folder as it seems the theme folder name can be different from the config name for themes, where modules can't.

Code: Select all

	protected function getTemplateCode($route, &$code) {
		if (!empty($code)) {
			return $code;
		}

		$template_file = DIR_TEMPLATE . $route . '.twig';
		
		if (str_contains($template_file, 'extension/ocmod')) {
			$route = str_replace('extension/ocmod/', '', $route);
			
			if (defined('DIR_CATALOG')) {
				$template_file = DIR_EXTENSION . 'ocmod/admin/view/template/' . $route . '.twig';
			} else {
				$template_file = DIR_EXTENSION . 'ocmod/catalog/view/template/' . $route . '.twig';
			}
		}
		
		if (file_exists($template_file) && is_file($template_file)) {
			return file_get_contents($template_file);
		} else {
			trigger_error("Cannot find template file for route '$route'");
			exit;
		}
		
	}

-
Image Image Image
VIEW ALL EXTENSIONS * EXTENSION SUPPORT * WEBSITE * CUSTOM REQUESTS


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK
Who is online

Users browsing this forum: No registered users and 0 guests