Post by 3rdcorner » Sun Dec 20, 2009 3:03 pm

Hi all, I'm new to the community but am a PHP dev myself and am adding OpenCart to my list of weapons :P

I like the MVC structure, code looks clean! I was wondering, is it a custom made framework or a spin-off of some other MVC styled framework?

In any case, I'm having trouble finding a good way to extend OpenCart. From what I see so far with modules and contributions is that they just overwrite core files.

What happens when I upgrade then? My store will be broken.

I was thinking, why not implement some kind of event based system like Wordpress has? Or, can I extend and override catalog/controller/common/header.php's index() function? How would the loader know I've done so?

I'm wondering because I'd like to develop some modules and make OpenCart one of the tools in my arsenal, and it's awesome that it uses MVC. But how am I supposed to keep track of each little modification I make to all the controller files, then I have to manually check my change log for each of my clients installations? On one client I just changed the header, on the other I rewired so much, I don't think I'd risk upgrading... ever... hahaha

Anyone know what I mean? I'm hoping that there's a programatically sound way to extend OpenCart... but from what I've seen the conrtibs are more like hacks... one that I just installed said 'over write x file and y file, and if you've installed a DIFFERENT module before, MERGE the changes!'

hahahaha, it's the same crap you have to deal with in all the other old school carts.

Don't get me wrong though, besides the non-existing plugin architecture OpenCart is awesome.

I propose we all help the creator and come up with a plugin architecture that makes sense, and doesn't break when you upgrade...

I've seen something, the addPreAction and dispatch functions... but there's little developer documentation.

I really like the coding style of OpenCart though... are there any other developers contributing?

New member

Posts

Joined
Sun Dec 20, 2009 2:35 pm

Post by readyman » Sun Dec 20, 2009 7:30 pm

I think I'm one of the guilty coders that are hacking the core, but as far as I can see, it seems to be the only way to make some changes to allow them to appear where they need to appear. eg. changes to the options.
If it's a totally new module or add-on (eg. a forum) then it would allow itself to become a library or extension, because it could sit alongside the existing classes, but in some cases it doesn't seem possible.

I would love to have a look at the wordpress style plugin architecture and see how they insert plugin specific functions into posts & pages (& what other types of insertion points can be supported & how). Usually there is always tweaking involved, but in terms of opencart, it would be great if this tweaking could be isolated to the views, rather than having to update the existing controllers and models.

Let's keep this discussion alive, I think it would be beneficial to see real code examples or discuss why things may or may not work for opencart.

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by 3rdcorner » Sun Dec 20, 2009 10:04 pm

Yes I've just gotten done with a round of hacking, had to edit the products model (catalog/model/catalog/product.php) so I could show the 4 latest products from our 5 most popular categories, and including all their children so that was a good couple of hours.

What I'm doing is adding a commented lines beginning where I change things and and end comment to signify that's where the normal file starts again. Upgrading will be tedious... but at least I'll know what I edited.

New member

Posts

Joined
Sun Dec 20, 2009 2:35 pm

Post by Xsecrets » Sun Dec 20, 2009 10:14 pm

Yes unfortunately right now you pretty much have to overwrite/edit the core file to get many things to work.
This has been discussed a few times.

Q has some good ideas as seen in this thread http://forum.opencart.com/viewtopic.php ... enu#p41536
I would love for Daniel to get in on this discussion and see if we can come up with something to be rolled into one of the next few versions of opencart. I think it would really help things moving forward.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by fido-x » Sun Dec 20, 2009 10:58 pm

3rdcorner wrote:... had to edit the products model (catalog/model/catalog/product.php) so I could show the 4 latest products from our 5 most popular categories, and including all their children so that was a good couple of hours.
You should have looked in "catalog/controller/common/home.php" (line 29):

Code: Select all

foreach ($this->model_catalog_product->getLatestProducts(8) as $result) {

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Mon Dec 21, 2009 12:41 am

3rdcorner wrote:From what I see so far with modules and contributions is that they just overwrite core files.
Negative. The Extension system uses completely standalone files and loads them dynamically.
At this time "Extensions" include
Sideboxes, payment, shipping, order totals, and feeds.
I was thinking, why not implement some kind of event based system like Wordpress has? Or, can I extend and override catalog/controller/common/header.php's index() function? How would the loader know I've done so?
Yes, I've been doing lots of searching for a good override system (see this thread) and you are correct that one is needed. I've also toyed with an SMF style approach where it modifies the file based on a patching/installer system that I've got working
I'm wondering because I'd like to develop some modules and make OpenCart one of the tools in my arsenal, and it's awesome that it uses MVC. But how am I supposed to keep track of each little modification I make to all the controller files, then I have to manually check my change log for each of my clients installations? On one client I just changed the header, on the other I rewired so much, I don't think I'd risk upgrading... ever... hahaha
Modules are transparent, but yes, core mods are definitely dangerous and each change should be documented and commented. You can try to also keep your changes local to the template file and use a custom template name so that updates don't overwrite. My override ideas from the other thread I linked above would solve some of this at the file level, but not at the individual function level.
Anyone know what I mean? I'm hoping that there's a programatically sound way to extend OpenCart... but from what I've seen the conrtibs are more like hacks... one that I just installed said 'over write x file and y file, and if you've installed a DIFFERENT module before, MERGE the changes!'
I think my explaination above should have cleared this up.
I really like the coding style of OpenCart though... are there any other developers contributing?
There are a few of us.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by 3rdcorner » Mon Dec 21, 2009 1:16 am

fido-x wrote: You should have looked in "catalog/controller/common/home.php" (line 29):

Code: Select all

foreach ($this->model_catalog_product->getLatestProducts(8) as $result) {
Yea I did, that's where I found that those products are loaded from the product model.

Thanks for all the replies, I'm reading those threads now.

New member

Posts

Joined
Sun Dec 20, 2009 2:35 pm

Post by wgn_white » Sat Mar 06, 2010 7:44 pm

WordPress plugin works by using hooks and filter function.
When the plugin is activated, it is "plugged" to the hook that placed on the main core function and on the front end template files.

Wordpress, instead of writing the new hacks into the core files.
It "hook" the new programming line into an empty function in the core files which act as a container for new programming line.
So its like we write the new hacks into the core file itself.
When the plugin is deactivated, the programming line then removed from the empty functions that serve as the container and we have been reverted to default.

We don't have to touch the core file at all.
I really hope that open cart can implement this type of architecture.

To have a hacks that appear where it should be, then we should put an optimum hooks at selected location as a container for new programming line and when we need to put something there such as sidebars, admin back end new tab, we just "hook" the new functions to that functions container.

I don't have a formal php lesson.
But I've been working with wordpress plugin for abour 2 years now and I am very happy that it is easy to extend wordpress for someone who learn php from University of Google... ;D

My Open Cart online shop: Guan8871 Free Shipping Online Shop
My personal blog: Wiguan88.com
Blog where I post my online activities such as web development: PANGERAN.ORG


User avatar
Newbie

Posts

Joined
Sat Mar 06, 2010 1:20 pm
Location - Malaysia

Post by Mucus » Sat Apr 24, 2010 1:10 am

Has there been any progress on the overrides idea? I've seen threads stretching back a couple of years, but so far no luck finding anything about it in the documentation. The reason I ask is I want to move a bunch of stuff from the header templates to the footer templates because I find the default templates a little top-heavy and I want the page content closer to the top of the HTML, but this means I also have to modify the controllers, and I guess the only clean way to do that will be through this discussed override functionality.

Newbie

Posts

Joined
Thu Apr 22, 2010 2:22 am

Post by Xsecrets » Sat Apr 24, 2010 1:28 am

Mucus wrote:Has there been any progress on the overrides idea? I've seen threads stretching back a couple of years, but so far no luck finding anything about it in the documentation. The reason I ask is I want to move a bunch of stuff from the header templates to the footer templates because I find the default templates a little top-heavy and I want the page content closer to the top of the HTML, but this means I also have to modify the controllers, and I guess the only clean way to do that will be through this discussed override functionality.
there is no override functionality at this point and time. Yes it's been discussed several times, but nothing has been done.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by Mucus » Sat Apr 24, 2010 1:35 am

I'm new with OpenCart, so does this mean I have to move the corresponding code from the header controller to the footer controller, or is there an easier/safer way? Specifically I'm referring to the language and currency dropdowns.
Last edited by Mucus on Sat Apr 24, 2010 1:37 am, edited 1 time in total.

Newbie

Posts

Joined
Thu Apr 22, 2010 2:22 am

Post by Qphoria » Sat Apr 24, 2010 1:36 am

Too much has been changing lately with the framework so I refrained from spending time on that until it settled down.
Perhaps now it is time to begin looking at that again.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Mucus » Sat Apr 24, 2010 1:41 am

Qphoria wrote:Perhaps now it is time to begin looking at that again.
That would be great, it would allow a whole other level of customizability.

That said, I'm extremely impressed with OpenCart, I've just completed my first fully customized template, it's just the inability to move code between files that's preventing me from going that extra step.

Newbie

Posts

Joined
Thu Apr 22, 2010 2:22 am

Post by Qphoria » Sat Apr 24, 2010 1:55 am

Mucus wrote: That said, I'm extremely impressed with OpenCart, I've just completed my first fully customized template, it's just the inability to move code between files that's preventing me from going that extra step.
Well I'm not sure how that would change from the override step. Override would just prevent core files from being overwritten.

Moving code around is different. I am looking into some hook options but its all up in the air still.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Mucus » Sat Apr 24, 2010 2:11 am

Qphoria wrote:Well I'm not sure how that would change from the override step. Override would just prevent core files from being overwritten.
Correct me if I'm wrong, but the header controller contains the data needed by the language module. If I move the language module from the header template to the footer template, I get the error "Notice: Undefined variable: languages in..." meaning I have to move a few lines from the header controller to the footer controller, but I'd rather not modify those files, but instead override them so they won't be overwritten when I upgrade OpenCart.

Newbie

Posts

Joined
Thu Apr 22, 2010 2:22 am

Post by Qphoria » Sat Apr 24, 2010 2:32 am

no the language stuff is in the index file. You likely just need to load the language file in the footer controller

$this->language->load('common/header');

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Mucus » Sat Apr 24, 2010 2:58 am

I'm talking about the language dropdown code that I want in the footer because it and the currency code and their associated javascript are too bulky to be in the header IMHO. Using CSS I can display them anywhere. This is the code I had to move to get rid of the error:

Code: Select all

$this->data['language_code'] = $this->session->data['language'];
		
$this->load->model('localisation/language');
		
$this->data['languages'] = array();
		
$results = $this->model_localisation_language->getLanguages();
	
foreach ($results as $result) {
	if ($result['status']) {
		$this->data['languages'][] = array(
			'name'  => $result['name'],
			'code'  => $result['code'],
			'image' => $result['image']
		);	
	}
}

Newbie

Posts

Joined
Thu Apr 22, 2010 2:22 am

Post by Qphoria » Sat Apr 24, 2010 4:07 am

Well overrides wouldn't help this. This kinda stuff really needs to be "tag" based where you can populate any template with a simple :
<?php echo $languagebox; ?>

This used to be like this in 1.3.2 and earlier when there was a common layout. It was extremely simple
Then someone got this idea to make the controller the parent file so that each controller could choose which children were loaded.. but since nobody cares about that, and the children list is still hardcoded anyway.. it was a huge step backwards. Perhaps in 1.5.x the template system can be changed (yet again) to be something more like joomla where the layout is completely independent of controller and you can have a simple layout that you just add the "tags" to... something like:

Code: Select all

<html>
<body>
  <div id="header">
    <?php echo $headerData; ?>
    <?php echo $search; ?>
    <?php echo $language; ?>
  </div>

  <div id="columnLeft">
    <?php echo $leftColumnData; ?>
  </div>

  <div id="columnRight">
    <?php echo $rightColumnData; ?>
  </div>

  <div id="content>
    <?php echo $contentData; ?>
  </div>

  <div id="footer>
    <?php echo $footerData; ?>
  </div>
</body>
</html>
Then you can add anything you want anywhere easily.

You can blame the community members that are also template creators for agreeing to the new design that started in 1.3.3. They all said they liked it... but Qphoria knew better ;)

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Mucus » Sat Apr 24, 2010 4:20 am

Agreed... your proposal would make life much easier.

Newbie

Posts

Joined
Thu Apr 22, 2010 2:22 am

Post by alanms » Fri Sep 03, 2010 10:35 am

Hi guys, great discussion, just wondering what the latest thinking is here? I saw http://forum.opencart.com/viewtopic.php?f=24&t=17143 - so it seems hook events are still in the pipeline as of July 2010. Just wondering if there's any tips on the shape these might be taking, for those of us needing to roll our own in the meantime.

I'm another newcomer to OC loving the crisp use of MVC, and working on a module that requires a function to occur with every successful call to model_checkout_order->confirm. So far, my module has kept core completely untouched, using $_GET and session data to make module functions roughly coincide with the appropriate core functions. That's not going to work for a model function.

I'd love to leave my clients with the simplest possible housekeeping instructions for when they wish to update OC. So, I'm just wondering: is there a better or more future-proof method to extend a vital Core function like this than tacking something like "if x module enabled, do y function from module" into function confirm(...) in model/checkout/order.php? Some method that is most in line with current thinking about how the future hook system might work?

If there's a clear direction emerging for how this will work, I could also be up for contributing what I can to help make it happen from my modest experience of hooks in Drupal.

Newbie

Posts

Joined
Fri Sep 03, 2010 10:01 am
Who is online

Users browsing this forum: No registered users and 126 guests