Post by k.garyfalos » Fri Apr 12, 2024 1:23 am

Hello Community,

I'm a developer and I want to create an extension for one of my clients for OpenCart for version 4.0.2.3. This extension will be of type "Theme" and I want it to have the following features:

1. I want to be able to run the files that will be in the extension instead of the ones that will be in the main catalog folder of the main OpenCart structure. I have completed this particular feature by customizing the example theme that OpenCart has preinstalled for us.

2. I want to be able to create a custom folder with a file (eg extension/extension_name/catalog/..../sections/portfolio) inside the extension, which will not exist in the main folder catalog of the main OpenCart structure and when I call from the frontend the page via $_GET (eg index.php?route=section/portfolio), it loads the content directly from the extension.

For the 2nd part, no matter what I've done it doesn't reroute me to the extension for the route parameter and it returns that the page doesn't exist because the file doesn't exist in the main catalog folder of the OpenCart main structure.

Below I present to you the progress of my extension so far which is located in the path extension/extension_name/catalog/controller/startup.

Code: Select all

<?php
namespace Opencart\Catalog\Controller\Extension\ThemeName\Startup;
class Settings extends \Opencart\System\Engine\Controller
{
	public function index(): void 
	{
		if ($this->config->get('config_theme') == 'settings' && $this->config->get('theme_ThemeName_status')) 
		{
			// Add event via code instead of DB
			// Could also just set view/common/header/before
			$this->event->register('view/*/before', new \Opencart\System\Engine\Action('extension/ThemeName/startup/Settings.event'));
	    }	
	}
	
	public function event(string &$route, array &$args, mixed &$output): void 
	{
		$override = 
		[
		    'common/header',
		    'common/home',
		    'common/maintenance',
		    'section/portfolio'
		];

		if (in_array($route, $override)) 
		{
			$route = 'extension/ThemeName/' . $route;
		}
	}
}
Thank you very much in advance

Newbie

Posts

Joined
Sun Nov 24, 2019 9:16 pm

Post by straightlight » Wed Apr 17, 2024 12:11 am

k.garyfalos wrote:
Fri Apr 12, 2024 1:23 am
Hello Community,

I'm a developer and I want to create an extension for one of my clients for OpenCart for version 4.0.2.3. This extension will be of type "Theme" and I want it to have the following features:

1. I want to be able to run the files that will be in the extension instead of the ones that will be in the main catalog folder of the main OpenCart structure. I have completed this particular feature by customizing the example theme that OpenCart has preinstalled for us.

2. I want to be able to create a custom folder with a file (eg extension/extension_name/catalog/..../sections/portfolio) inside the extension, which will not exist in the main folder catalog of the main OpenCart structure and when I call from the frontend the page via $_GET (eg index.php?route=section/portfolio), it loads the content directly from the extension.

For the 2nd part, no matter what I've done it doesn't reroute me to the extension for the route parameter and it returns that the page doesn't exist because the file doesn't exist in the main catalog folder of the OpenCart main structure.

Below I present to you the progress of my extension so far which is located in the path extension/extension_name/catalog/controller/startup.

Code: Select all

<?php
namespace Opencart\Catalog\Controller\Extension\ThemeName\Startup;
class Settings extends \Opencart\System\Engine\Controller
{
	public function index(): void 
	{
		if ($this->config->get('config_theme') == 'settings' && $this->config->get('theme_ThemeName_status')) 
		{
			// Add event via code instead of DB
			// Could also just set view/common/header/before
			$this->event->register('view/*/before', new \Opencart\System\Engine\Action('extension/ThemeName/startup/Settings.event'));
	    }	
	}
	
	public function event(string &$route, array &$args, mixed &$output): void 
	{
		$override = 
		[
		    'common/header',
		    'common/home',
		    'common/maintenance',
		    'section/portfolio'
		];

		if (in_array($route, $override)) 
		{
			$route = 'extension/ThemeName/' . $route;
		}
	}
}
Thank you very much in advance
section/portfolio is not among the extension folder. You're declaring the route as a core path and the extension path can only rely on the core. Therefore, you'd need to ensure your new / custom routes are being declared from the extension folder. Otherwise, you'll need to use OCMod to alter the startup/permission routes to accept your new route of: section/portfolio.

Alternatively, using OCMod altogether in OC 4 may become even more handy to achieve this type of project later on.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 8 guests