Page 1 of 3

Combining OpenCart with Wordpress

Posted: Mon May 11, 2009 7:36 pm
by pee
Hi,

I want to combine OpenCart with wordpress. Is it possible to display the header-area with login, cart etc. in an Iframe?

Best regards! O0

Re: Combining OpenCart with Wordpress

Posted: Fri Jul 31, 2009 4:33 am
by vince79
Not sure that the iframe solution is right.

However, it would be great to be able to use a Wordpress template for Opencart...
At least for the header / footer / sidebar.

Would that be possible ?

Re: Combining OpenCart with Wordpress

Posted: Fri Jul 31, 2009 5:04 am
by Qphoria
another user i know uses an iframe and it works ok. He disabled the opencart header and just uses his site header.

Re: Combining OpenCart with Wordpress

Posted: Sun Aug 02, 2009 1:49 pm
by yuwenlong126
good idea

Re: Combining OpenCart with Wordpress

Posted: Sun Dec 20, 2009 11:51 am
by huhitschris
I've successfully combined a wordpress installation with an opencart installation, it's not too difficult if you know both systems fairly well. The easiest way to do this is to create a wordpress installation as you normally would, then create a directory inside the wordpress installation directory that would contain the opencart installation.

should look like...

/path/to/wordpress/index.php
/path/to/wordpress/opencart/index.php

This way you are able to allow both frameworks to operate normally without modifying the core files very much. You'll still need to modify your opencart header, home, footer, etc. to match your wordpress theme's layout and stylesheet. If you want opencart data on your wordpress pages you'll need to write custom php/mysql functions into your wordpress theme to pull from the opencart database.
vince79 wrote:Not sure that the iframe solution is right.
Agreed.
pee wrote:I want to combine OpenCart with wordpress. Is it possible to display the header-area with login, cart etc. in an Iframe?
If all you want is login, cart, etc. then just put your opencart install in it's own directory and create links to the appropriate destinations on your wordpress template.

example:

Code: Select all

<a href="path/to/shop/index.php?route=account/login">Login</a>

Code: Select all

<a href="path/to/shop/index.php?route=checkout/cart">Cart</a>
The only difficulty is that you can't check if you are logged in or not from wordpress, so a dynamic log in or log out isn't an option unless you want to write a function to check the opencart session.

Re: Combining OpenCart with Wordpress

Posted: Sat Feb 06, 2010 6:09 pm
by nocko
huhitschris wrote:
This way you are able to allow both frameworks to operate normally without modifying the core files very much. You'll still need to modify your opencart header, home, footer, etc. to match your wordpress theme's layout and stylesheet. If you want opencart data on your wordpress pages you'll need to write custom php/mysql functions into your wordpress theme to pull from the opencart database.
I've started by transplanting the opencart "environment" from index.php and planting them into wordpress' index.php. The next step I would imagine is to copy the proper header MVC files over to the wordpress directory to allow a dynamic login/cart in wordpres' header. Is this what you mean?

Re: Combining OpenCart with Wordpress

Posted: Sun Feb 07, 2010 5:33 am
by huhitschris
No what I'm talking about is you leave the two installations alone. Let them operate independently, just skin the two to have identical templates, you may even want to reference the same CSS file in the headers of both. From there you can write your own code to access functions across systems.

Example: http://www.coastalcityclothing.com

The OpenCart is in it's own subdirectory 'shop' under the WordPress install directory. The WordPress links to the store giving you the feeling that the store is just it's own page but really you're now looking at OpenCart themed to match the WordPress theme.

One thing to consider when combining the two frameworks is the routing of your URLS. Both of them have their own ways of dealing with routing and I think it's better to steer clear of having to deal with modifying those.

Also, if you start merging the controllers and such of each framework you're shit out of luck when you want to upgrade either one of them.

If you find a way that works better without causing problems please do let us know.

Re: Combining OpenCart with Wordpress

Posted: Sun Feb 07, 2010 7:38 am
by Daniel
this is really good stuff. this should be posted in the wordpress contribution section.

Re: Combining OpenCart with Wordpress

Posted: Sun Feb 07, 2010 7:59 pm
by 3rdcorner
So far I've gotten wordpress to pull in customer login information from OpenCart by including the bare minimum requirements for /system/library/customer.php

Here's what I include in my wordpress header.php:

Code: Select all

require_once('./shop/config.php');
//require_once(DIR_SYSTEM . 'startup.php');
require_once(DIR_SYSTEM . 'engine/registry.php');
require_once(DIR_SYSTEM . 'library/session.php');
require_once(DIR_SYSTEM . 'library/request.php');
require_once(DIR_SYSTEM . 'library/db.php');
require_once(DIR_SYSTEM . 'library/customer.php');
	
// Session
$session = new Session();
Registry::set('session', $session);

// Request
$request = new Request();
Registry::set('request', $request);

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
Registry::set('db', $db);

$customer = new Customer();
$logged = $customer->isLogged();
Then, in my header links I can see if we're logged in with open cart so I can display the right shop links:

Code: Select all

<div id="shop_links">
					<ul>
						<li class="inline"><img	src="<?php echo get_bloginfo('url'); ?>/shop/catalog/view/theme/default/image/icon_special.png"	alt="MMA Specials" class="icon"	/><a href="<?php echo get_bloginfo('url'); ?>/shop/product/special">Specials</a></li>
						<?php if (!$logged): ?>
						<li class="inline lock"><img	src="<?php echo get_bloginfo('url'); ?>/shop/catalog/view/theme/default/image/icon_login.png"	alt="Login" class="icon"	/><a href="<?php echo get_bloginfo('url'); ?>/shop/account/login">Log In</a></li>
						<?php else: ?>
						<li class="inline"><img	src="<?php echo get_bloginfo('url'); ?>/shop/catalog/view/theme/default/image/icon_logout.png" alt="Logout"	class="icon" /><a	href="<?php echo get_bloginfo('url'); ?>/shop/account/logout">Log Off</a></li>
						<li class="inline"><img	src="<?php echo get_bloginfo('url'); ?>/shop/catalog/view/theme/default/image/icon_account.png"	alt="Account" class="icon"	/><a href="<?php echo get_bloginfo('url'); ?>/shop/account/account">Account</a></li>
						<?php	endif; ?>
						<li class="inline"><img src="<?php echo get_bloginfo('url'); ?>/shop/catalog/view/theme/default/image/icon_checkout.png"	alt="Shopping Cart" class="icon"	/><a	href="<?php echo get_bloginfo('url'); ?>/shop/checkout/cart">Cart</a></li>
					</ul>
					<div class="clear"></div>
						
				</div> <!--	div#shop_links -->
The overhead is a bit much when you include everything from both systems, so I've come up with different ways of doing things.

For example, on the homepage I want a drop down navigation of all the shop's categories and sub-categories. I've used the native Open Caching feature, and save the entire navigation with the cache, then load it from my home.php in Wordpress.

For the above examples live check out: http://www.knockoutathletics.com

I also made a one page checkout for that site.

What I'm trying to do now with a different site is kind of opposite. I'd like to include the Wordpress libraries into OpenCart so I don't have to go thru the trouble of modifying a lot when I convert the OpenCart theme to the site's Wordpress theme.

Re: Combining OpenCart with Wordpress

Posted: Sun Feb 07, 2010 8:13 pm
by huhitschris
Yea I like the idea of caching the output of one system in order to provide data to the other and minimize the overhead.

I was just thinking about how you might be able to get blog posts into your OpenCart installation without having to connect to the WP database....

Grab the RSS feed from your WordPress install using SimpleXML, then parse and display the feed however you like from your OpenCart - caching of course. Still, this is a lot of overhead but if anyone is looking for a quick and hackish way to get the job done this is one option.

Re: Combining OpenCart with Wordpress

Posted: Sat Feb 13, 2010 8:45 am
by 3rdcorner
huhitschris wrote:Grab the RSS feed from your WordPress install using SimpleXML, then parse and display the feed however you like from your OpenCart - caching of course. Still, this is a lot of overhead but if anyone is looking for a quick and hackish way to get the job done this is one option.
I'd also cache the posts from within the wordpress template, depending on what category you're displaying in opencart.

It's not hackish IMO, wordpress needs a proper caching mechanism anyways. Right now there's a few out there, SuperCache is the best IMO, coupled with a CDN it's pretty good. From what I hear, places like Digg and Slashdot just upgrade their hardware and do no-duh optimization like mysql query optimization and caching, gzip, cdn, and compress and concatenate js/css.

Re: Combining OpenCart with Wordpress

Posted: Sat Feb 13, 2010 3:51 pm
by fireatwire
3rdcorner wrote: I also made a one page checkout for that site.
Your one-page-checkout seems really great! Would be really awesome if you could post your code and template changes for that solution...

Re: Combining OpenCart with Wordpress

Posted: Sun Feb 14, 2010 3:47 am
by 3rdcorner
I plan to open all my modification (hacks really) on a site sometime soon.

I made a new onepage.php controller file and basically merged all the functions into one file, and also made a few new .tpl files for the views. The language is used from the guest checkout lang files, but I manually overrode some to just say 'Checkout.'

It also doesn't support a payment address and shipping address, it just uses your shipping address as the credit card verification modules don't require it anyways.

If you're logged in, it grabs your information and you see most of the checkout process on one page, otherwise the logged out version relies heavily on ajax to grab the proper stuff.

Currently this is the only solution I could offer the client with his budget, but I'd ideally make a non-javascript version. I don't think it's too much of an issue though, because javascript is required for Open Cart to properly function anyways.

Re: Combining OpenCart with Wordpress

Posted: Fri Feb 19, 2010 5:01 pm
by hubmachine
hi hut

I like your post about combining opencart and wordpress a lot. This is excactly the thing I was looking for!
Your site looks very nice and opencart is integrated in a smooth way. I would like to have the same result for my site. :)

I wanna combine my already existing site with opencart. Now I have some questions to your post.
If I got you right, you kept the both systems separated. In different folders as you described. What I'm not sure about is the way of calling opencart.

In the way you did it, is opencart running within the wordpress theme (layout) or is it running just on its own?
Did you adapt the layout opencart home.tpl to your sites layout? So it looks like it's integrated? So you have the layout of your site doubled. One time in wordpress and the same look in home.tpl? This way you didn't have to modify the front-controller requests... Did I got you right this way?

Kind regards
hubmachine

Re: Combining OpenCart with Wordpress

Posted: Fri Feb 19, 2010 6:55 pm
by huhitschris
Yes, the easiest thing to do is install the two separately in their own folders, OpenCart being in a subdirectory of your WordPress install like I mentioned earlier.

The reason I suggest OpenCart inside of WordPress folder is because of how URLs are routed for each and I very much prefer to leave the routing systems alone and let them do their business as usual while avoiding making .htaccess changes.

To get the same look and feel you need to theme your WordPress and OpenCart exactly the same. In my example I even set up both to refer to the same CSS file so that I wouldn't have to repeat myself. You may want to have a few common includes for things like headers, navigation or the footer for both.

After you theme them both to look the same you will now have a blog & shopping cart working side-by-side but appearing to be all part of one package.

The reason I recommend this method is because at this point you've left the core files untouched for both frameworks, so you haven't broken anything and everything should be working as it normally would.

From here on out if you want to start crossing over data between the two systems you can start with all the modding but at least you're starting with a fresh install.

My example is a very simple example of the two running side-by-side without any complicated calls.

Keep in mind that some simple things don't need to be made complicated. If you want to feature a few store items on your blog, just hand-code the HTML to link to your product pages. Don't drive yourself crazy modding controller files and such to achieve the same effect through the back-end unless you really need it.

If you are interested in calling OpenCart functions from your blog, you might try using an AJAX request to send data to one of your OpenCart controllers which will then respond back with the data you are trying to get.

So for example your blog's sidebar might ask for index.php?route=products/category/list to return to you a list of categories. You would just create a function called list() in your controller/products/category.php file and tell it to respond with the data you need. I haven't tried this yet but it seems like something that could very easily be done and would be useful as some kind of sidebar store navigation on your blog.

I can't really tell you where to go from there, it's up to you and whatever creative ideas you can come up with. Hit me up if you have any more questions.

O0

Re: Combining OpenCart with Wordpress

Posted: Thu Mar 25, 2010 1:55 am
by superann
I'm working on a site using OC and WP (http://beta.poketo.com/) and ended up doing pretty much what 3rdcorner did above, so thanks for that! I actually implemented things first using Ajax to pull the login links and cart items/total summaries (just stuck a new method in an existing controller that spit out what I needed) but I prefer it this way as I usually like having a non-JS dependent fallback.

Re: Combining OpenCart with Wordpress

Posted: Wed Apr 14, 2010 10:01 am
by migz
I'm going to combine this the other way around
/ = opencart
/blog = wordpress

I'll just create a new a link in opencart to /blog
then theme the /blog the same as opencart.

But I have a problem, i want to integrate the users in opencart to wordpress, so they don't have to type their name anymore when they comment. Is it possible to do this? What do you guys think?

Re: Combining OpenCart with Wordpress

Posted: Wed Jul 14, 2010 4:14 pm
by banane
following the suggestions above we've done that: http://www.valier.it
is still the first attempt (we hope do to something better) and the english translation is still in progress..

Re: Combining OpenCart with Wordpress

Posted: Sat Jul 24, 2010 4:11 pm
by sabresports
I really hope someone can help because all my wishes would finally become a reality as far as developing sites using opencart and wordpress together.

I am constructing a new website at http://www.sportsvalue.co.uk. I have wordpress and opencart currently working side-by-side seamlessly together. I have managed to integrate wordpress into opencart without too many problems, the horizontal navigation bar runs from the wordpress 3.0 menu on all pages.

3rdcorner seems to be barking up the right tree but I just can't seem to get things to work. Any help will be very much appreciated!

My wish is simple, I need to integrate the category list menu module + small shopping basket module + a dynamic log in menu in the header from opencart into my wordpress pages.

Re: Combining OpenCart with Wordpress

Posted: Wed Jul 28, 2010 5:28 pm
by moyger
I have installed opencart on the root folder and make folder /contents/ for the wordpress. Now what I want is to have the login/logout. I have tried the sample above....

require_once('/home/stir001/public_html/config.php');
//require_once(DIR_SYSTEM . 'startup.php');
require_once(DIR_SYSTEM . 'engine/registry.php');
require_once(DIR_SYSTEM . 'library/session.php');
require_once(DIR_SYSTEM . 'library/request.php');
require_once(DIR_SYSTEM . 'library/db.php');
require_once(DIR_SYSTEM . 'library/customer.php');


but this resulted me to an error:
Fatal error: Using $this when not in object context in /home/stir001/public_html/system/engine/registry.php on line 10

So I assumed it doesn't read the "$this" coz it's in the opencart application somewhere declaring classes inside. Is there any solution for this?

I need the wordpress to know if the user is logged in/out in opencart and display the correct Login link.

Hope anyone can help....Here's my site....http://www.stirringhearts.com.sg.

Some pages are in Wordpress like going to Dedication page(http://www.stirringhearts.com.sg/contents/?page_id=10)

Thanks in advance!!