Post by dfumagalli » Wed Aug 28, 2013 10:15 pm

I'd have a suggestion.

It'd be nice to have:

1) An easy to call, official "IsOverrideEngineInstalled()" function to quickly detect if your framework is installed. Modders would use that call to display a "OE not detected please install from <link>" or even perform an automated installation (like qQModerator does for vQMod).

2) A sort of "Installation success checker" php file. Basically a guy would install your framework and then enter an URL and would see something like:

- Checking if I can instantiate a class from the factory
- Checking for blah blah (basic sanity checks)

"OE succesfully installed"

3) A commented "Hello world" mod skeleton (maybe optional download) to help OE modders get started. After all vQMod comes with examples and the Hostjars website provides an OC module builder and even an OC module creator.

4) A badge, that is an icon that modders can put in their admin section or wherever (maybe embed the code to instantiate it directly in the framework) that says: "Powered by OE framework".
Nothing fancy, just something like the W3C badge you can get if your site validates:

Image

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by dfumagalli » Thu Sep 05, 2013 10:52 pm

I have just found a little issue.

OE has born to let extend OC easier.
However I did not find an easy way to extend OE itself.

Use case:

- I created a memcached cache manager for OC.
- I need to instantiate and use it in place of the default cache class.

In original OC, I'd open index.php and would replace:

$cache = new cache();

with

$cache = new mycache();

With OE I have to go dig what

$cache = $factory->newCache();

does.

In system/engine/factory.php I find:

public function newCache() {
return $this->newSystemClass( 'library/cache.php' );
}

Now, in an ideal OOP world I'd expect:

1) public function newCache( $cacheImpl = 'library/cache.php' ) {
return $this->newSystemClass( $cacheImpl );
}

where I can customize the php file I include. This is really easy to implement in the OE core *hint* ;)

2) Ability to inherit

class Factory {
}

and override the newCache() method with my own.

But no, Factory declaration starts with

final class Factory
{

so I can't inherit from it.

What shall I do? A vQMod of factory.php? Sounds quite weird to have to hack in with vQMod into the core of the Engine born to avoid using vQMod.

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by JNeuhoff » Thu Sep 05, 2013 11:50 pm

The Override Engine does not use the Decorator Pattern. Rather, it is a mechanism for independent addons to extend core Opencart classes. In your example, you could do something like this (assuming your addon is named mycache):

Create an override/mycache/system/library/cache.php with something like this:

Code: Select all

<?php  
class mycache_Cache extends Cache {

	// overridden method
	public function get($key) {
		// do my own stuff
		// ........
		return parent::get($key);
	}

	// overriden method
	public function set($key, $value) {
		// do my own stuff
		// ........
		parent::set($key,$value);
	}
	..........
}
?>
If you are sure that no other addon happens to extend the same class, you don't have to call the parent methods.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by dfumagalli » Mon Sep 09, 2013 4:45 pm

Thank you so much for the example!

I only have a doubt left about it: how do I tell Opencart's very engine that from now on it has to use a MyCache instance in place of the default class type?

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by JNeuhoff » Mon Sep 09, 2013 6:49 pm

dfumagalli wrote:Thank you so much for the example!

I only have a doubt left about it: how do I tell Opencart's very engine that from now on it has to use a MyCache instance in place of the default class type?
The factory will detect the existence of an extended Cache class automatically. The factory class is reponsible for creating instances of Opencart core classes, see e.g.

$cache = $factory->newCache();

in the index.php.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by dfumagalli » Tue Sep 10, 2013 10:11 pm

Thank you. After further fiddling with class names vs path names and similar I got it working.

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by dfumagalli » Thu Oct 10, 2013 4:07 pm

Hello again,

I have been directed here by another poster after I created this thread.

Basically, I'd like a way to intercept calls to controllers so that, in case of invalid controller name I don't get an ugly blank page (with or without PHP Notice printed on it) but I can redirect the user back to the home page.

Is this something managed by OE or that I can manage by subclassing an OC file with OE?

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by JNeuhoff » Thu Oct 10, 2013 6:16 pm

You could use PHPs set_error_handler and register_shutdown_function to capture all kinds of errors and to do a graceful exit, e.g. a redirection to a dedicated error page or the home page.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by dfumagalli » Mon Oct 14, 2013 3:51 pm

JNeuhoff wrote:You could use PHPs set_error_handler and register_shutdown_function to capture all kinds of errors and to do a graceful exit, e.g. a redirection to a dedicated error page or the home page.
Thank you,

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by dfumagalli » Wed Oct 23, 2013 6:59 am

Hello,

I have another question.

I noticed OE forces vQMod to ignore controller.php

So I created a /override/FWMods/system/engine directory and put a derived class with this code:

Code: Select all

<?php

class FWMods_Controller extends Controller
{
    protected function render($CacheTimeout = 0) {
		foreach ($this->children as $child) {
			$this->data[basename($child)] = $this->getChild($child);
		}

                if ($this->factory) {
(I can't use protected function preRender( $templateBuffer ) )

However my override does not get invoked, ever. Other overrides do but this one won't, I checked step by step with XDebug.

Is it intended?

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by JNeuhoff » Wed Oct 23, 2013 4:29 pm

This is intended. The system/engine/controller.php is part of Opencart's core engine and should never be modified.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by dfumagalli » Wed Oct 23, 2013 6:48 pm

JNeuhoff wrote:This is intended. The system/engine/controller.php is part of Opencart's core engine and should never be modified.
I have both 3rd party and in house made mods that need to modify it.
Last edited by dfumagalli on Thu Oct 24, 2013 12:51 am, edited 1 time in total.

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by dfumagalli » Wed Oct 23, 2013 11:40 pm

Another question (yes I am very curious). I ask it to you because I see the OE customizations at work in there.

I have noticed that the Controller::render function has 3 sections:

1) One deals with the children.
foreach ($this->children as $child) {
$this->data[basename($child)] = $this->getChild($child);
}
2) One checks for $this->factory != NULL, reads the template, assigns variables and renders the output, then it returns (so the 3rd is not executed).

Code: Select all

		if ($this->factory) {
			$prefix = $this->factory->getIsAdmin() ? 'admin_view_template_' : 'catalog_view_theme_';
			$template_id = $prefix.str_replace( array('/','.'),array('_','_'),$this->template );
			$GLOBALS[$template_id] = $this->preRender( $this->factory->readTemplate( $this->template ) );
			extract($this->data);
			ob_start();
			/* Could have used the standard data://text/plain buffer stream, 
			   e.g. require("data://text/plain;base64,".base64_encode($buffer))
			   but it is not always supported on cheaper web hosts.
			   Instead we use our own variable stream var://<global-var-id> based on library/variable_stream.php.
			*/
			require("var://".$template_id);
			$this->output = ob_get_contents();
			ob_end_clean();
			return $this->output;
		}
3) One reads the template, assigns variables and renders the output

Code: Select all

if (file_exists(DIR_TEMPLATE . $this->template)) {
			extract($this->data);
			
			ob_start();
	
			require(DIR_TEMPLATE . $this->template);
	
			$this->output = ob_get_contents();

			ob_end_clean();
			
			return $this->output;
		} else {
			trigger_error('Error: Could not load template ' . DIR_TEMPLATE . $this->template . '!');
			exit();
		}
What's exactly the point of section 3?
I have debugged it and it never gets executed, neither as front end nor in the admin.
It lacks a call to $this->preRender() so this function meant to intercept rendering seems not be invoked from this section.

So, when does section 3 come into play? If so, why no call to $this->preRender() in there?

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by JNeuhoff » Thu Oct 24, 2013 1:04 am

You are right, section 3 never gets executed. It's just old code from the original controller.php, just part of my overly defensive programming style, in case something is corrupted with the OE.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by dfumagalli » Sat Nov 23, 2013 9:07 pm

Hello,

I am back with another of my silly questions.
I am unit testing my OpenCart installation and my add ons.

Since my classes also use Override Engine, I had to include it when my tests are being performed.

But I hit a snag: looks like PHPUnit creates its own var:// wrapper so OE bombs out with:

stream_wrapper_register() /var/www/doman.tld/public_html/system/engine/factory.php:73
PHP Notice: Failed to register protocol for a variable stream in /var/www/domain.tld/public_html/system/engine/factory.php on line 75

Is there any way to make PHPUnit and OE co-exist together? It'd be nice to have OE auto-detect if the stream wrapper was already created and use it without exiting.

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by dfumagalli » Wed Nov 27, 2013 6:01 pm

I am posting what I have found, for the posterity.

This is included in a StackOverflow.com question and answer.

Heavy OpenCart Customizations. Current project in progress: fleurworld.com


Active Member

Posts

Joined
Tue Aug 20, 2013 3:34 am

Post by JNeuhoff » Wed Nov 27, 2013 7:40 pm

I think the next version of the Override Engine will use dynamically generated class files in system/cache instead of the VariableStream. This will also make debugging easier.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by straightlight » Thu Dec 12, 2013 5:50 am

is it going to be by author from the system/cache folder ?

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by JNeuhoff » Thu Dec 12, 2013 6:47 am

straightlight wrote:is it going to be by author from the system/cache folder ?
No.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Qphoria » Thu Dec 12, 2013 10:16 pm

straightlight wrote:is it going to be by author from the system/cache folder ?
lol I think we can let this idea die.. it isn't planned to happen in any of the modification/override systems.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 5 guests