Mage Enabler: A plugin to run Magento's session within WordPress

In: Feeling guru|Techie Daw

11 May 2010

Mage Enabler

Update (May 12, 2010): Mage Enabler is now available in the Official WordPress Plugin repository. Get it here!

It’s been a while since I posted my tweak that allows Mage object to be utilized within any WordPress installation. The tweak requires the blog owner to modify functions.php as stated in my post. I’m inspired by the feedback of the readers who used the tweak so I decided that a plugin that does the same thing should be made to prevent modifying the WordPress core files thus preventing the tweak to cause inconsistencies when an upgrade is necessary.

It is my pleasure to introduce to you, Mage Enabler plugin. Just copy the whole code snippet below and save it as mage-enabler.php. Place it inside a folder named mage-enabler together with the readme.txt available right after the code block. Please take time to read and follow the readme.txt instruction on how to install the plugin in your WordPress setup.

How to use the plugin?

To show you how the plugin works, I’ve decided to convert my example in my previous post by providing a single login page for both WordPress (subscriber) and Magento (customer). This setup assumes that the account credentials (subcriber/customer) in both database are the same and that the function collision problem between WordPress and Magento has been fixed. If you followed the functions.php update in that post, remove the block of code added at line 4123 to 4138.

Location of functions.php

path-to-your-root-htdocs/wordpress/wp-includes/functions.php

Let’s start by opening the index.php file of the WordPress theme Twenty Ten. I’m using version 3.0-beta1 of WordPress in this article. You can replicate the same code update to any WordPress version and theme you have.

wordpress_root\wp-content\themes\twentyten\index.php

Copy the necessary codes (lines 16-18 and 22-40) to make it similar below:

<?php

/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty Ten
 * @since 3.0.0
 */
 if(class_exists('Mage')){
 	Mage::getSingleton('core/session', array('name' => 'frontend'));
 }
?>

<?php get_header(); ?>
<!-- Magento's custom greeting -->
<div style="font-size: 15px; margin-bottom: 15px; border-bottom: 1px solid #000; padding-bottom: 10px;">
<?php
if(class_exists('Mage')){
	$session = Mage::getSingleton("customer/session");
	$magento_message = "Welcome ";
	// Generate a personalize greeting
	if($session->isLoggedIn()){
		$magento_message .= $session->getCustomer()->getData('firstname').' ';
		$magento_message .= $session->getCustomer()->getData('lastname').'!';
	}else{
		$magento_message .= "Guest!";
	}

	echo $magento_message;
}
?>
</div>
<!-- End of Magento's custom greeting -->

The purpose of the code change above is to display a ?Welcome [customer name here]? when a customer is logged in, and show ?Welcome Guest? when they are not. Make sure that if you’re going to use any Magento related script in your code, always write it within the following if condition:

if(class_exists('Mage')){
	// Write your Magento codes here
}

This will prevent your page or theme files from breaking up if in case the plugin is deactivated, not working or if Mage.php can’t be found.

Open user.php file found at following address below:

path-to-your-root-htdocs/wordpress/wp-includes/user.php

Locate the function wp_authenticate_username_password() and find the similar code below. I found mine at line 108.

	if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) )
		return new WP_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: Incorrect password. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login')));

Right after the code above, add the following code starting at line 111 to make it similar to the code below. This update allows us to run the login request of Magento within WordPress:

	if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) )
		return new WP_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: Incorrect password. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login')));
	// Start Magento
	if(class_exists('Mage')){
		Mage::getSingleton('core/session', array('name' => 'frontend'));
		$session = Mage::getSingleton("customer/session");
		try{
			$login = $session->login($username, $password);
		}catch(Exception $e){
			// Do nothing
		}
	}

Finally, to call the Magento’s logout function, locate the file below and open it:

path-to-your-root-htdocs/wordpress/wp-login.php

Find the switch case statement at line 352. Add the necessary code to make it similar to the code below and save it:

switch ($action) {

case 'logout' :
	check_admin_referer('log-out');
	// Start Magento
	if(class_exists('Mage')){
		Mage::getSingleton('core/session', array('name' => 'frontend'));
		Mage::getSingleton("customer/session")->logout();
	}
	wp_logout();

Now test your WordPress by accessing the homepage at http://localhost/wordpress/. It should display the ‘Welcome Guest’ similar to the image below with a cookie named as ‘frontend’ in your Firebug cookie tab. That is your Magento cookie.

A Test WordPress homepage showing the default welcome message for Magento

A Test WordPress homepage showing the default welcome message for Magento

Clicking the login for WordPress redirects us to the login form like the one below while still showing the ‘frontend’ cookie. Since I have a customer with same credentials on both Magento (Customer) and WordPress (set as Subscriber), all I have to do is to use the username and password to login in the form below.

A Test WordPress login page with a generated Magento cookie

A Test WordPress login page with a generated Magento cookie

At this point, your Magento session should be running with an active customer session. To check if it does, go back to your homepage by clicking the top header text or going to http://localhost/wordpress/. It should display now the welcome message with your customer’s name.

A Test WordPress homepage showing the customer's name in the welcome message

A Test WordPress homepage showing the customer's name in the welcome message

For those who will use this plugin, let me know the version of WordPress and Magento you’re using so I can keep track of the list of versions in which this plugin is compatible. Until such time that the plugin is moved to the Official WordPress Plugin repository, I’ll accept and answer inquiries here thru comment/feedback form below. Mage Enabler is now available in the Official WordPress Plugin repository. Get it here!

About the author

Richard Feraro is a Magento Enterprise Certified developer from Manila, Philippines with 14 years of solid open-source development experience using Linux, Apache, MySQL & PHP.

205 Responses to Mage Enabler: A plugin to run Magento's session within WordPress

Avatar

How to use Magento’s session within WordPress « My Silly Point of View UNITED STATES

May 11th, 2010 at 10:48 pm

[…] How to use Magento’s session within WordPress by Richard Feraro on April 8, 2010 Update (May 11, 2010): I created a WordPress plugin for this one. Check it out here. […]

Avatar

Fred UNITED STATES

May 12th, 2010 at 5:17 pm

Hello:
Could not get this to activate. “Invalid – no header” error message.

Avatar

Richard Feraro UNITED STATES

May 12th, 2010 at 6:17 pm

first, set your error_reporting to E_ALL to see the actual error.
what’s your WordPress and Magento version?

Avatar

louie PHILIPPINES

May 12th, 2010 at 5:27 pm

my website wont display anything after the plugin is activated.

Avatar

Richard Feraro UNITED STATES

May 12th, 2010 at 6:17 pm

set your error_reporting to E_ALL to see what’s your error.

Avatar

Kiper IT-konsult SWEDEN

May 25th, 2010 at 1:27 am

Great work Richard!

This is really getting interesting. I have been using Joomla with Magento for a couple of webshops but it feels like overkill most of the time. So a WordPress-Magento bridge plugin looks like a killer app!

I hope I will have time testing it during the summer…

Avatar

Richard Feraro UNITED STATES

May 25th, 2010 at 5:13 pm

Thanks Kiper! Send a feedback of your testing either here or in the Mage Enabler page in the plugin repository in WordPress so I can improve it.

Avatar

Greg Lutz UNITED STATES

May 27th, 2010 at 3:35 am

Darn – went back and changed the code, but now there’s no statement showing up.

Avatar

Richard Feraro PHILIPPINES

May 27th, 2010 at 9:24 am

Check the following:

  1. Is Mage Enabler installed?
  2. Is it Activated?
  3. Did you supply the absolute URL of your Mage.php? Which of the following below is displayed when you supply the absolute URL?
    • Invalid URL
    • File is accessible!
    • Mage object not found!

Avatar

Greg Lutz UNITED STATES

May 28th, 2010 at 2:38 pm

Looks like I have a final step of adding the Absolute URL:
Here’s the location of the Mage.php
/html/app/Mage.php
Wondering what I put into the Absolute URL field.
Aloha,
Greg
I’m hoping this will enable the Welcome Guest! comment to show.

Avatar

Richard Feraro UNITED STATES

May 28th, 2010 at 2:45 pm

Put that /html/app/Mage.php address in the absolute URL textbox and Save the setting. It will display a message beside the box if it’s working properly.

Avatar

Camilo Sanchez DOMINICAN REPUBLIC

June 7th, 2010 at 4:29 am

Hi Richard, first thank you for this awesome plugin, this is just great work!
I’ve installed the plugin and followed all the instructions as you said in this post but i have some trouble and i don’t know what is causing it. My problem is I’m getting the “Welcome Guest!” text but when i login into wordpress it remains the same. it doesn’t reflect my username, I can see the “frontend” cookie showing up. When I go to magento the same happens, it doesn’t show my username. What am i doing wrong? Another question i have, since is a little bit confusing for me is do i need to be registered in magento and wordpress with the same user and same password in both platforms? sorry if this last question is silly, I have little programming skills.
I’m using wordpress 3.0 and magento 1.4. Another thing I’m seeing is two frontend cookies, one for magento and another for wordpress. Thank you in advance for your help!

Avatar

Richard Feraro

June 7th, 2010 at 11:35 am

Hi Camilo πŸ™‚

Thanks for using the plugin and reading my blog. Regarding your question, if you follow the modification in index.php, user.php and wp-login.php, manually create the same username and password in Magento and WordPress. Just go through the usual way registering to each application then test it again. That’s what I did to test if it works πŸ™‚

Thanks again.

Richard

Avatar

Gregg UNITED STATES

June 8th, 2010 at 3:16 am

first, great blog! second, Im having an issue getting this to work. I have the plugin installed and it points to the absolute url for Mage.php at /var/www/vhosts/….etc

I have all php errors turned on at .htaccess level in WP, but im still only seeing a blank white page.

any help would be great! im using latest WP and Mage.

What I am trying to do get the head, header and footer from Magento to be displayed on the WP install.

thanks in advance!

Avatar

Richard Feraro UNITED STATES

June 8th, 2010 at 6:54 pm

Hello Gregg,

Try placing the error_reporting(E_ALL) within the file your working on just above the script where you added the Magento call. It happened to me one time when I tried to declare the error_reporting in .htaccess but still got a blank screen. Let me know the output. Blank screen means there’s a Fatal error within the file.

Thanks.

Avatar

Gregg UNITED STATES

June 10th, 2010 at 1:32 am

thanks Richard,

i realized I needed to get rid of Magento’s __() function so I did add the /app/code//local/Mage/Core/functions.php tweak you suggested.

now my error is related to another plugin (wordpress breadcrumbs), so thanks for the help! you got me in the right direction.

Avatar

Richard Feraro UNITED STATES

June 10th, 2010 at 2:26 am

Hi Greg,

If you’re already using the Mage Enabler plugin, you don’t have to edit and add the tweak to functions.php anymore since the plugin already does that for you. You still need to get rid of the Magento’s __() translation function though.

Ooops! My bad πŸ™‚ I thought you we’re referring to WordPress’ functions.php. Glad that you were able to solve it πŸ™‚

Thanks πŸ™‚

Avatar

mik ITALY

June 14th, 2010 at 7:30 pm

Hallo Richard,
very useful plugin and very well supported tru your blog.
I’ve successfully get rid of magento ___() function, installed mage-enabler and get the right absolute URL for for mage.php.
Now, I’m not very interested in the double log in but I just want the magento store running inside my wp! I’m a little puzzled about where to place the call to magento. I’m thinking about create a wp-page called store, create a template for it and inserting the call to magento stuff in there (as described in the various comment to this and to the other post). Is it correct?

Thank you for doing this!

Bye

Avatar

Richard Feraro UNITED STATES

June 14th, 2010 at 7:59 pm

Hello Mik! Thanks for spending time reading my article.

Yes, you’re right regarding the technique you mentioned. The best places I think to add the Magento call are the following files within your template folder: index.php, header.php or try functions.php if you’re template has one. Just make sure you’re Magento call is on top of the page where there’s no header request or you’ll encounter the error I mentioned in the post. You can test which one is the right file for your template by checking if you’re blog creates a frontend cookie when accessed thru a browser.

Avatar

mik ITALY

June 14th, 2010 at 11:43 pm

Hallo Richard, well spent time reding your blog πŸ˜‰

Back to php stuff, I’ve put the php call ( * Run Magento’s Mage.php within WordPress
etc…) inside my wp-content/theme/mytheme/functions.php
Than, I’ve created a template to embed the magento code in my wp’s “store” page
and placed the function BEFORE the header call, like this:

<?php
/*
Template Name: store
*/
magento();
?>
<?php get_header(); ?>

So I’ve put some simple magento code in the page wrapped in if function

<?php
if(class_exists('Mage')){
	// Write your Magento codes here

require_once 'app/Mage.php';
umask(0);
//not Mage::run();
Mage::app('default');

//code snipped
$className = Mage::getConfig()
            ->getBlockClassName('catalog/product_events');
$block = new $className();

$block->setTemplate('catalog/product/homepageevents.phtml');

echo $block->renderView();
}?> 

but I still get the infamous Fatal error: Uncaught exception ‘Exception’ with message ‘Warning: session_start() etc etc (20 lines…)

Where did I get wrong?

Thanks a lot

Avatar

Richard Feraro PHILIPPINES

June 15th, 2010 at 2:16 am

If you have installed and activated the Mage Enabler plugin and supplied the absolute URL with no error after saving it, you don’t have to use magento() anymore. You also don’t need the following lines because the plugin already does this for you:

...
require_once 'app/Mage.php';
umask(0);
//not Mage::run();
Mage::app('default');
...

You just have to use the following code at the top of your page where you want to call Magento’s object (this is the one that creates the frontend cookie):

// Start Magento
if(class_exists('Mage')){
    Mage::getSingleton('core/session', array('name' => 'frontend'));
}

in the same file but in a different location depending on what you’re trying to do, add your own Magento calls:

if(class_exists('Mage')){
    //code snipped
    $className = Mage::getConfig()->getBlockClassName('catalog/product_events');
    $block = new $className();
    $block->setTemplate('catalog/product/homepageevents.phtml');
    echo $block->renderView();
}

Avatar

mik ITALY

June 16th, 2010 at 11:32 pm

Hi Richard,
I’ve tryied going the easy way as you described: no more fatal error and the frontend cookie appears.

I’ve my ‘store.php’ page with //start magento on top (before header!) and the code snipped you’ve suggested somewhere in the page where’d like to dislplay the magento’s stuff. But I get this error loading the page:

Fatal error: Class ‘Mage_Catalog_Block_Product_Events’ not found in /var/www/myhost/wordpress/wp-content/themes/mytheme/store.php on line 46

here comes the pages’s code:

<?php
/*
Template Name: store
*/
// Start Magento
if(class_exists('Mage')){
    Mage::getSingleton('core/session', array('name' => 'frontend'));
}

?>

<?php get_header(); ?>
<div class="clear"></div>	
<div id="catmenucontainer">
	<div id="catmenu">
<!--
			<ul>
				<?php wp_list_categories('sort_column=name&title_li=&depth=4'); ?>
			</ul>
-->
	</div>		
</div>
<div class="clear"></div>
<div id="content_store">

<!-- inserting magento's ciccia -->
<?php
if(class_exists('Mage')){
    //code snipped
    $className = Mage::getConfig()->getBlockClassName('catalog/product_events');
    $block = new $className();
    $block->setTemplate('catalog/product/homepageevents.phtml');
    echo $block->renderView();
}?> 

<!-- end ciccia -->

	<div id="navigation">
	<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>  
	</div>

</div>


<?php get_footer(); ?>

I can feel I’m close to the solution…

Thank you for your commitment!

bye

mik

Avatar

mik ITALY

June 16th, 2010 at 11:34 pm

ehm I realize there’s some italian language left in the comments, btw ‘ciccia’ stands for ‘stuff’ πŸ˜‰

Avatar

Richard Feraro PHILIPPINES

June 17th, 2010 at 1:46 am

Yeah I saw that one hehehe πŸ™‚

Avatar

mik ITALY

June 16th, 2010 at 11:49 pm

My bad, I see I were trying to add stuff I didn’t have on my magento such as ‘catalog/product_events’ or ‘catalog/product/homepageevents.phtml’

I’ve tried inserting instead the code for the cart and … uuuuu … it works!
Now I’ve understand how to handle this magento code…

Thanks a lot for your help!

mik

Avatar

Richard Feraro PHILIPPINES

June 17th, 2010 at 1:49 am

Great! I’m glad that you were able to figure it out on your own. πŸ™‚ Keep on reading mik!

Avatar

Richard Feraro UNITED STATES

July 3rd, 2010 at 12:13 am

Check out my latest post regarding this one.

Avatar

Michael UNITED KINGDOM

July 1st, 2010 at 12:04 am

Nice plugin but just dosen’t seem to work for me… I have tried both theories (the plugin & manually adding the script) i get all the signs of it working i.e the frontend coming through the wp-login HOWEVER…. I can’t seem to get it login in via my wordpress and make it login through magento,
I m using WP 3 magento 1.4, what i have noticed is that when you login to wordpress you are asked for your USERNAME and PASSWORD, when you login to Magento it asks you for EMAIL ADDRESS AND PASSWORD.. I am assuming this is why you can login via wordpress to both WP & Magento?

Cheers
Michael

Avatar

Richard Feraro PHILIPPINES

July 1st, 2010 at 1:21 am

Hello Michael,

I think you only missed one thing. Check the comments of Jim and my reply to him in this post

(clue: For testing purposes…)

Also on this same page, I also mentioned it.

Thanks for reading the article πŸ™‚

Avatar

mik ITALY

July 4th, 2010 at 4:58 pm

Hallo Richard, here I come again!

I’ve a new problem since I’m using the xml-rpc API [http://codex.wordpress.org/XML-RPC_wp] it works like a charm until I activate the mage-enabler plugin. When I turno on your plugoin the xmlrpc.php goes nuts and report this error:

Fatal error: Uncaught exception 'Exception' with message 'Warning: Varien_Autoload::include(WP/User/Search.php) [<a href='varien-autoload.include'>varien-autoload.include</a>]: failed to open stream: No such file or directory in /var/www/mysite/magento/lib/Varien/Autoload.php on line 93' in /var/www/mysite/magento/app/code/local/Mage/Core/functions.php:248 Stack trace: #0 /var/www/mysite/magento/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'Varien_Autoload...', '/var/www/mysite...', 93, Array) #1 /var/www/mysite/magento/lib/Varien/Autoload.php(93): Varien_Autoload::autoload() #2 [internal function]: Varien_Autoload->autoload('WP_User_Search') #3 [internal function]: spl_autoload_call('WP_User_Search') #4 /var/www/mysite/wordpress/wp-admin/includes/user.php(472): class_exists('WP_User_Search') #5 /var/www/mysite/wordpress/wp-admin/includes/admin.php(46): require_once('/var/www/mysite...') #6 /var/www/mysite/wordpress/xmlrpc.php(54): include_once('/var/www/mysite...') #7 {main} thrown in /var/www/mysite/magento/app/code/local/Mage/Core/functions.php on line 248

Any idea?

thx

bye

mik

Avatar

Richard Feraro PHILIPPINES

July 4th, 2010 at 7:50 pm

The xmlrpc setting is found in an admin page. Are you doing any Magento calls within the admin? There’s nothing in the error that says Mage Enabler is the culprit. The xmlrpc in my blog is actually enabled too with Mage Enabler installed as well.

Avatar

mik ITALY

July 4th, 2010 at 10:50 pm

uhm, actually it shouldn’t be any connection bettween mage enabler and the xmlrpc. I’m using it just to get an xml list of wp pages to create a flash menu. but without even linking magento or any wp pages with magento the file at http://mydomain.com/xmlrpc.php stops working. I was just wandering how it would be that xmlrpc get an error related to a magento’s function!

Avatar

Richard Feraro UNITED STATES

July 6th, 2010 at 10:41 pm

Hey mik, found out that this is a bug. I already updated the plugin. Please download the latest version.

See the Changelog. Thanks for the feedback.

Avatar

mik ITALY

July 8th, 2010 at 7:42 pm

Hallo Richard, glad to be helpful. I’ve installed the latest mage-enabler version and now the xmlrpc goes like a charme. Unfortunately now I get a similar conflict/error with the popular plugin swf-object:

Fatal error: Uncaught exception 'Exception' with message 'Warning: Varien_Autoload::include(Swfobject.php) [<a href='varien-autoload.include'>varien-autoload.include</a>]: failed to open stream: No such file or directory in /var/www/toystoys/magento/lib/Varien/Autoload.php on line 93' in /var/www/toystoys/magento/app/code/local/Mage/Core/functions.php:248 Stack trace: #0 /var/www/toystoys/magento/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'Varien_Autoload...', '/var/www/toysto...', 93, Array) #1 /var/www/toystoys/magento/lib/Varien/Autoload.php(93): Varien_Autoload::autoload() #2 [internal function]: Varien_Autoload->autoload('swfobject') #3 [internal function]: spl_autoload_call('swfobject') #4 /var/www/toystoys/wordpress/wp-content/plugins/nextgen-gallery/lib/swfobject.php(2): class_exists('swfobject') #5 /var/www/toystoys/wordpress/wp-content/plugins/nextgen-gallery/widgets/widgets.php(53): require_once('/var/www/toysto...') #6 /var/www/toystoys/wordpress/wp-content/plugins/nextgen-gallery/widgets/widgets.ph in /var/www/toystoys/magento/app/code/local/Mage/Core/functions.php  on line 248

My silly solution is just to comment out line 248 in var/www/mysite/magento/app/code/local/Mage/Core/functions.php

throw new Exception($errorMessage);

Well, know the error doesn’t show in wp anymore and swf-object plugin is back to work as usual. Even Magento seems running quite well, anyhow I suppose there’s something wrong.

Your thoughts?

Thank you

-mik

Avatar

Richard Feraro UNITED STATES

July 8th, 2010 at 8:06 pm

What’s the name of the plugin? Is it the Nextgen gallery plugin?

Avatar

mik ITALY

July 8th, 2010 at 8:27 pm

You get it! Even if the plugin reported in the error is swfobject http://wordpress.org/extend/plugins/wp-swfobject the error appears on an instance of Nextgen gallery’s slideshow (using imagerotator.swf). It’s a known bug?

Avatar

Richard Feraro UNITED STATES

July 8th, 2010 at 10:46 pm

I’m not sure yet unless I could see how that plugin works. Any sample site where I can see the error? How about additional details such as which file is showing an error? Does this error occurred prior to your xmlrpc.php inquiry? How can I replicate the error on your end?

Avatar

cody MALAYSIA

July 9th, 2010 at 4:20 pm

i can’t get the valid Mage.php address.
where can i find it?

Avatar

Richard Feraro UNITED STATES

July 9th, 2010 at 4:32 pm

Are you using windows or linux? Mage.php is found in /your-web-root/magento-root-folder/app/Mage.php

Avatar

cody MALAYSIA

July 10th, 2010 at 9:33 am

im using windows, n my hosting is linux. i can only found /wp-content/plugins/mage-enabler. but cant find any other magento folder. is it i miss any step for installing?

Avatar

Richard Feraro PHILIPPINES

July 10th, 2010 at 1:47 pm

I see. You don’t have Magento installed. You have to install it. Download it here.

Avatar

Mark UNITED STATES

July 12th, 2010 at 8:09 pm

I am trying to get the magento header to display in wordpares using

if(class_exists('Mage')){
$className = Mage::getConfig()->getBlockClassname('page/html_header');
$block = new $className();
$block->setTemplate('page/html/header.phtml');
echo $block->renderView();

The logo and slogan images display but its missing links, cart, search and menu.

Any ideas?

Avatar

Richard Feraro UNITED STATES

July 12th, 2010 at 8:36 pm

Hi Mark,

Thanks for reading the article. If you check my example above, it doesn’t have the links, cart info and other information you’re looking for because it is the header block only. The HTML blocks you’re looking for are found in the other blocks such as ‘catalogsearch/form.mini.phtml’ and ‘catalog/navigation/top.phtml’.

Check the comments of peaker from the other article on how he did it here.

Avatar

Richard Feraro UNITED STATES

July 12th, 2010 at 8:44 pm

I also posted a script which pulls the rest of the links and search box too here.

Avatar

Mark UNITED STATES

July 13th, 2010 at 5:37 am

Perhaps I am a little slow today. I took a look at the other comments but I must be missing something.

How would I do the following for topLinks?

getChildHtml('topLinks')
	$topLinks = $magento_block->createBlock('???/???');
	$topLinks->setTemplate('???/???');
<?php if(class_exists('Mage')){ echo  $topLinks->toHTML(); } ?>

Thanks.

Avatar

Richard Feraro UNITED STATES

July 13th, 2010 at 3:15 pm

I don’t use getChildHtml(…). I use Mage::getSingleton(‘core/layout’) since it is easier and more manageable.

http://mysillypointofview.richardferaro.com/2010/07/03/how-to-add-magento-blocks-css-and-javascript-to-an-external-site/

Avatar

Mark UNITED STATES

July 14th, 2010 at 5:23 am

I get this error.

Fatal error: Call to undefined function isloggedin() in /public_html/blog/wp-content/themes/twentyten/index.php on line 12

Here is my code.

<?php
// Start Magento
if(class_exists('Mage')){
    Mage::getSingleton('core/session', array('name' => 'frontend'));
}

?>

<?php get_header(); ?>

<?php
if(isLoggedIn()){
		$magento_message .= $session->getCustomer()->getData('firstname').' ';
		$magento_message .= $session->getCustomer()->getData('lastname').'!';
	}else{
		$magento_message .= "Guest!";
	}

# Initiate Blocks
$linksBlock = $magento_block->createBlock("page/template_links");

$checkoutLinksBlock = $magento_block->createBlock("checkout/links");
$checkoutLinksBlock->setParentBlock($linksBlock);

$wishlistLinksBlock = $magento_block->createBlock('wishlist/links');
$wishlistLinksBlock->setParentBlock($linksBlock);

# Add Links
$linksBlock->addLink($linksBlock->__('My Account'), 'customer/account', $linksBlock->__('My Account'), true, array(), 10, 'class="first"');
$wishlistLinksBlock->addWishlistLink();
$checkoutLinksBlock->addCartLink();
$checkoutLinksBlock->addCheckoutLink();

if ($session->isLoggedIn()) {
    $linksBlock->addLink($linksBlock->__('Log Out'), 'customer/account/logout', $linksBlock->__('Log Out'), true, array(), 100, 'class="last"');
} else {
    $linksBlock->addLink($linksBlock->__('Log In'), 'customer/account/login', $linksBlock->__('Log In'), true, array(), 100, 'class="last"');
}
?>
echo $magento_message.''.$linksBlock->renderView().'';

?>

<!-- End of Magento's custom greeting -->

Funny thing is when I first got this I removed that section and the links came up but but know if i remove it i get “Call to a member function createBlock() on a non-object in…”. Looks like something else might have been changed.

Thanks,
Mark

Avatar

Richard Feraro UNITED STATES

July 14th, 2010 at 3:10 pm

Is this this the first time you used Magento (just asking)?
Read here on how to call isLoggedIn() method of Magento.

Avatar

Bill UNITED STATES

July 14th, 2010 at 10:34 pm

Thanks for this awesome extension. I’m wondering about the customer/user tables within the two applications, does it interfere with rights assigned from the backend to the logged in user of either app? Is a customer that checks out a wp user and if not how could we sync the two?

Avatar

Richard Feraro UNITED STATES

July 15th, 2010 at 10:45 pm

Hi Bill, thanks for the feedback.

Regarding your question, the plugin does not interfere with whatever access rights and permission assigned to the user in both application by default. Since the plugin somewhat provides you with raw access to Mage object, it can however modify a user’s permission through that.

The user by default isn’t logged in automatically on Magento when they access and logged in to WordPress. In order to do that, you can use the Mage object also to login the user in Magento automatically upon logging in to WordPress like my example in the other article I posted last April. You might wanna read my reply to a user named Jim because it could be relevant to what you want to achieve in your application. Check it here.

Avatar

Bill UNITED STATES

July 17th, 2010 at 3:10 am

Richard,

Thank you for your response. I was able to configure WordPress as the root domain and Magento as a subdirectory or domain.com/shop. I’ve installed the mage enabler and got an error message until I made the adjustments to magento’s functions.php. My problem is creating a subscriber in WordPress does not create the customer in magento and the code example on running magento’s session within wordpress does not pull magento’s header or anything into it.
Wordpress say’s it see the mage.php. Do I have to make any further code adjustments, scowering your blog I’m getting a little confused with exactly what to modify. My idea is to run a blog with buddypress plugin and a magento shop. I need to have a wordpress subscriber created once a customer creates an account during checkout. I’d also like to have a magento customer created when a subscriber creates an account from wordpress. You mentioned I could use a single table for customers/subscribers but this maybe a little beyond me. Synchronizing Magento’s customers to WordPress subscribers would be fine handled because not all subscribers would be customers. Can you see any way to accomplish this? Thanks again for your assistance.

Avatar

Richard Feraro

July 17th, 2010 at 11:56 am

Hi Bill,

The only thing that Mage Enabler does is to include Mage.php in your WordPress instance and run Mage::app(‘default’). You have to code the rest of the functionality that you need to implement in your WordPress. I do posted some samples here which are as follows:

Inserting blocks, CSS and JS files from Magento to WP
Single login between Magento and WP (although the actual user creation isn’t included)

The codes below can also be applied:
Adding products with custom options
Cancel Cart/Quote of Magento from external site
Check the login status of a customer

Plus, there are a lot of examples in the net that uses Magento’s Mage.php can also be used with Mage Enabler.

Avatar

Bill UNITED STATES

July 18th, 2010 at 9:27 pm

Ok I was confused. I thought this plugin would enable WordPress to Magento capability for a normal WordPress user. It would be nice if you could package up some type of communication between the two systems that would allow a normal WordPress user to use Magento’s capabilities within WordPress. I’m not putting you down at all for this contribution it’s just a little confusing and time consuming to implement. Having a single sign on between the two applications would be nice along with passing customers, orders and content between the two frameworks.

Avatar

Richard Feraro

July 18th, 2010 at 10:37 pm

I think you’re looking for a different plugin and Mage Enabler isn’t for you. Like what you said, you want to use WordPress to your Magento. That’s not what Mage Enabler is for. What the plugin does is to use Magento into WordPress using its session not the other way around. Lazzymonks plugin for Magento us what you need.

Avatar

Bill UNITED STATES

July 18th, 2010 at 9:31 pm

Ok maybe not the actually content because each application does quite well with managing it along. I’d just like to be able to pass customers that signup from the Magento checkout through to WordPress as subscribers or other role.

Avatar

Richard Feraro

July 18th, 2010 at 10:43 pm

Mage Enabler doesn’t do that. If your primary is purpose is to let Magento do the managing of user roles from Magento to WordPress, better look for a Magento plugin in Magento Connect.

Avatar

Chris UNITED STATES

July 19th, 2010 at 11:27 pm

I’m trying to get your plugin to work but keep getting the invalid url message. I have magento set up as a root install and wordpress in installed in a root folder.

They are both installed in their own databases.

The url for the mage file is http://mywebdomain.com/app/Mage.php.

Should they be sharing the same database? Is there a problem with the way they are installed?

Thanks in advance.

Avatar

Richard Feraro

July 21st, 2010 at 2:42 am

I?m trying to get your plugin to work but keep getting the invalid url message. I have magento set up as a root install and wordpress in installed in a root folder.

They are both installed in their own databases.

The url for the mage file is http://mywebdomain.com/app/Mage.php.

You need the local absolute URL not the web address.

Should they be sharing the same database? Is there a problem with the way they are installed?

The database has nothing to do with your error. The plugin only need an absolute URL.

Look or search for the word “absolute” in the comments area in this page so you’ll have an idea what is Mage.php’s absolute URL.

Avatar

Chris

July 21st, 2010 at 3:42 am

Hey Richard,

I think I got the right url, i’m now getting this error message;

Cannot redeclare __autoload() (previously declared in /home/mysite/public_html/wordpress/wp-content/plugins/connect2MAGE/connect2MAGE.php:52) in /home/mysite/public_html/app/code/core/Mage/Core/functions.php on line 69

Avatar

Richard Feraro

July 21st, 2010 at 10:21 am

That’s not my plugin. It’s connect2Mage like what the error shows. Also, I would expect the same error with any plugin that uses the same application (Magento) since they both utilize the same function. Your error says __autoload() is already declared because you’re using two plugins that links to the same single external application.

Avatar

Chris UNITED STATES

July 21st, 2010 at 10:17 pm

sorry about that, here’s the error w/out the other plugin activated:

Fatal error: Cannot redeclare __() (previously declared in /home/mysite/public_html/wordpress/wp-includes/l10n.php:96) in /home/mysite/public_html/app/code/core/Mage/Core/functions.php on line 96

Avatar

Richard Feraro UNITED STATES

July 21st, 2010 at 10:35 pm

It’s the function collision between Magento and WordPress. Read the article above, the solution is found in the first paragraph of ‘How to use the plugin?’ section with a link provided on how to fix it.

Avatar

Chris

July 22nd, 2010 at 4:49 am

The way I understood that paragraph was that anything that your previous posts stated to do were not required since t you released the plugin. Might make it more clear if you added it to the read me file. Thanks for your help.

Avatar

Richard Feraro PHILIPPINES

July 23rd, 2010 at 4:50 am

I think you misunderstood that phrase. It was never mentioned in any of my post that “that anything that your previous posts stated to do were not required since t you released the plugin“. If you read the article and comments here, you will know that it is referring to the code below which was mentioned in this page too (see comment):

...
require_once 'app/Mage.php';
umask(0);
//not Mage::run();
Mage::app('default');
...

Maybe you were referring to this comment too? The tweak mentioned here is the function magento() added in the WordPress functions.php which was the original code before the plugin even existed. That function magento() also contains the very same code:

...
require_once 'app/Mage.php';
umask(0);
//not Mage::run();
Mage::app('default');
...

The plugin as stated in the description, requires PHP programming. That’s why I don’t see the point why would I tell the readers here to ignore the Magento/WordPress related articles I’m tirelessly posting here in my blog.

Avatar

Chris UNITED STATES

July 21st, 2010 at 10:34 pm

update: ok i deleted the line 96 which is the translate line you have crossed out above response,

“If you?re already using the Mage Enabler plugin, you don?t have to edit and add the tweak to functions.php anymore since the plugin already does that for you. You still need to get rid of the Magento?s __() translation function though.”

Thanks for your patience, now I to actually get the cool stuff happening….

Avatar

Jason Demant REPUBLIC OF KOREA

July 26th, 2010 at 10:17 am

Hi Richard,

Working on changing the way I integrate Magento and WordPress to use your new plugin and I’m running into a (hopefully easy-to-fix) issue.

I’ve installed the plugin, filled in the absolute path to the Mage.php (File is accessible!). In one of my pages, at the very top of the file I’ve added the following:

if(class_exists(‘Mage’)){
echo “YES”;
}

And nothing happens, apparently the Mage class doesn’t exist. What am I missing?

I’m using WP 3.0 and Magento 1.4.0.1.

Thanks as always!
Jason

Avatar

Richard Feraro PHILIPPINES

July 26th, 2010 at 11:13 am

Hi Jason πŸ™‚

When you say ‘nothing happens’, does it mean the page is blank or the rest of the page shows except the word ‘YES’?

Avatar

Jason Demant REPUBLIC OF KOREA

July 26th, 2010 at 12:49 pm

Sorry, should have been clearer. The rest of the page shows, except the word “YES”.

Avatar

Jason Demant REPUBLIC OF KOREA

July 26th, 2010 at 5:28 pm

Hey Richard,

I was running into this issue locally, so I decided to test further to see if I could replicate the issue on my server. And oddly, it works fine on my server. It’s strange that it doesn’t work locally. I’m running Xampp locally, but have never really run into an issue where something doesn’t work locally, but works online. If you happen to have any thoughts, would definitely appreciate it.

Thanks again,
Jason

Avatar

Richard Feraro UNITED STATES

July 26th, 2010 at 6:35 pm

I do have several setup of different version of WordPress including Thelonious. All of them are using Mage Enabler plugin running in XAMPP for Windows (XP). Hmm, could it be a cache issue? Is the file you’re using a template file or some built-in WordPress core files?

Avatar

Richard Feraro UNITED STATES

July 26th, 2010 at 6:31 pm

Can you check if it created a cookie named ‘frontend’ using Firefox?

Avatar

Jason Demant REPUBLIC OF KOREA

July 30th, 2010 at 11:33 am

Hi Richard,

Unfortunately, still not working locally. I made sure the cache wasn’t an issue and created an else clause to make sure the page outputs at least something and it does…what I put in my else clause.

The file I’m running is a template file. I create a “Page” in WordPress and then choose the template file as the template. Which is the exact thing I do on my live server, which oddly works.

I checked to see if a cookie is being created in Firefox and it’s not. Just to double-check, I looked at the page online and it is creating a cookie. Very strange!

If you have any other recommendations, please let me know.

Thanks for your help as always!

Jason

Avatar

Richard Feraro UNITED STATES

July 30th, 2010 at 5:39 pm

Hmm, that’s weird. If you get the ‘File is accessible!’ message in the admin, it means Mage object is existing like what the plugin code says:

$message = ( class_exists( 'Mage' ) ) ? 'File is accessible!' : 'Mage object not found!';

Try doing the code below on the same page your working on. Is should show an array of all the classes that has been declared.

echo "<pre>";
print_r(get_declared_classes());
echo "</pre>";

Do this code also. It will generate the cookie named ‘frontend’. If it does then it should be working properly.

if(class_exists('Mage')){
	// Instantiate session and generate needed cookie
	Mage::getSingleton('core/session', array('name' => 'frontend'));
}

Avatar

Jason M UNITED STATES

July 26th, 2010 at 6:18 pm

Hi Richard,

I tried searching everywhere and can’t understand why I keep getting “invalid Url” it’s maddening. I’ve tried the only absolute url i know which is “http://mysite.com/public_html/shop/app/mage.php” but it still will not work. I know someone else asked the same question, but I couldn’t find a concrete example of what it should look like. I even checked out the post on wordpress.org that you replied to, like 2 hours ago, but that didn’t work either. I would love to get this working:)

Avatar

Richard Feraro UNITED STATES

July 26th, 2010 at 7:02 pm

Try this:

Navigate to your Magento installation. Locate and open the .htaccess file using a text editor:
/magento/app/.htaccess

Comment out the content per line. It should look like something similar below:
#Order deny,allow
#Deny from all

We did this to disable the restriction in viewing files under this directory. You MUST restore this later.

Create a file under the same directory and rename it with a .php extension name. Open this file and add the following lines:

<?php
phpinfo();

Save the file and access it via browser (http://your.magento.com/app/your-file-here.php).
Locate the line that says:

SCRIPT_FILENAME C:/xampp/htdocs/magento/app/your-file-here.php

Just replace your-file-here.php with Mage.php and copy the whole URL to the Mage Enabler setting textbox and hit Save.

DO NOT FORGET TO DO THIS
Restore your .htaccess to its original content like the one below or everyone will be able to access your Mage.php publicly:
Order deny,allow
Deny from all

Delete your-file-here.php that you created earlier. The content of this file will expose most of your Apache server settings.

Avatar

Jason M UNITED STATES

July 26th, 2010 at 7:06 pm

I Fixed the absolute URL, Now I get a fatal error. What could this be from? I don’t have any SEO plugin installed either.
Fatal error: Uncaught exception ‘Exception’ with message ‘Warning: include(All/In/One/SEO/Pack.php) [function.include]: failed to open stream: No such file or directory in /home

Avatar

Richard Feraro UNITED STATES

July 26th, 2010 at 7:17 pm

It doesn’t show anything related to Mage Enabler plugin or even Magento itself. Is that the whole error?

Avatar

Jason M UNITED STATES

July 27th, 2010 at 8:04 am

I get the following fatal error after successfully linking Mage.php and after I’ve followed all the instructions in this post. I’m useing WP 3.0 and Magento 1.4. If I comment whatever is at line 248 on the functions php the error goes away but loging into mageto with WP credentials doesn’t work. Thank you for checking it out.

Fatal error: Uncaught exception ‘Exception’ with message ‘Warning: include(All/In/One/SEO/Pack.php) [function.include]: failed to open stream: No such file or directory in /home/myserver/public_html/shop/lib/Varien/Autoload.php on line 93′ in /home/myserver/public_html/shop/app/code/local/Mage/Core/functions.php:248 Stack trace: #0 /home/myserver/public_html/shop/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, ‘include(All/In/…’, ‘/home/myserver/…’, 93, Array) #1 /home/myserver/public_html/shop/lib/Varien/Autoload.php(93): Varien_Autoload::autoload() #2 [internal function]: Varien_Autoload->autoload(‘All_in_One_SEO_…’) #3 /home/myserver/public_html/wp-content/themes/Apz/functions/admin-functions.php(1097): spl_autoload_call(‘All_in_One_SEO_…’) #4 /home/myserver/public_html/wp-content/themes/Apz/header.php(5): woo_title() #5 /home/myserver/public_html/wp-includes/theme.php(1086): require_once(‘/home/myserver/…’) #6 /home/myserver/public_html/wp-includes/theme.php(1062): load_t in /home/myserver/public_html/shop/app/code/local/Mage/Core/functions.php on line 248

Avatar

Richard Feraro UNITED STATES

July 27th, 2010 at 4:18 pm

The All in One SEO Pack plugin for WordPress seems to conflict with Mage Enabler. There’s an spl_autoload_call(?All_in_One_SEO_??) in your theme files that triggers the error. I’ll investigate on the matter and see what can be done.

Avatar

Richard Feraro UNITED STATES

July 27th, 2010 at 4:41 pm

I installed the All in One SEO Pack and activated both plugins but didn’t get the same error that you have. See image below:

All in One SEO Pack plugin with Mage Enabler enabled

Avatar

Richard Feraro UNITED STATES

July 27th, 2010 at 4:10 pm

Your complete error shows that you have the All in One SEO Pack installed.
.../home/myserver/public_html/wp-content/themes/Apz/functions/admin-functions.php(1097): spl_autoload_call(?All_in_One_SEO_??)

Avatar

Joseph UNITED STATES

August 10th, 2010 at 6:10 am

Greetings Richard,

Thanks for developing Mage Enabler! It looks like it’s exactly what I’m looking for.

Since I’m a stronger designer than developer, I was hoping you could give me some advice…

I want to create a store within a WP website. By using Mage Enabler, will I be able to conduct transactions through WP, or will I have to link visitors to a Magento site? I guess I’m trying to figure out what comes first, the Magento site or WP?

Do you happen to have a step by step post on building a WP and Magento store? How about any link to sites that are doing that?

THANKS FOR YOUR TIME AND CONSIDERATION!!! Truly appreciate it!

Best
Joseph Rubio (Los Angeles)

Avatar

Richard Feraro UNITED STATES

August 10th, 2010 at 4:08 pm

Hello Joseph, thanks for taking time checking out my blog. Regarding your question, extending Magento to WordPress using its Mage object is like doing php programming and communicating with a third-party’s application API. In this case, you’re dealing with the Mage class and using its methods to do similar tasks present in the actual Magento instance to your external site (WP). What Mage Enabler does is to allow that Mage object to be instantiated within you WP, making all Magento’s methods accessible from within your blog. That why it is possible to use all the functionality mentioned in the Magento documentation.

Your setup may vary from one project to another. At one instance you may just need to run a WordPress as front end and Magento’s Admin panel so the default Magento front end isn’t used. Sometimes you may want to use both application’s front end, only getting portions of the functionality from Magento. Either way, it is possible. I still don’t have a step by step converting a WP into a full E-commerce site using Magento but there’s already a lot of blogs, post and articles dealing with manipulation of Mage object by including Mage.php within an external site (which is what Mage Enabler does.)

Avatar

Richard Feraro UNITED STATES

August 10th, 2010 at 9:30 pm

By the way, I moved your comment from the About section to this post since it’s about Mage Enabler.

Avatar

Vali ROMANIA

August 22nd, 2010 at 1:14 pm

Richard, your plugin is exactly what i was looking for for some time now.
What I am trying to to is to insert a product page into a blog post or a blog page. As i am not an experienced Magento developer, i was thinking that you might help me a bit with this one. Let’s say i want to insert the content of product with id 1000. Could you show a few line of code of how to do that from inside wordpress after installing your plugin?
Thanks

Avatar

Richard Feraro UNITED STATES

August 23rd, 2010 at 7:07 pm

Check this post. It has an example found in the first comment.

Avatar

Vali ROMANIA

August 25th, 2010 at 4:22 am

Richard , I want to thank you for your help and for developing this great plug in. It saved me a lot of time and effort .

Avatar

Richard Feraro UNITED STATES

August 25th, 2010 at 3:17 pm

You’re welcome Vali! Keep on reading πŸ˜›

Avatar

Christopher NORWAY

September 1st, 2010 at 6:22 pm

Hi Richard,

A genius plugin for sure. Thank you for sharing it.

Some feedback though. You have hard-coded the ‘default’ store code into the plugin. My magento site does not have a default store – it looks a bit like this.

website 1 (private), store 1 code: private_nbno
website 1 (private), store 2 code: private_engb
website 2 (wholesale), store 1 code: wholesale_nbno
website 2 (wholesale), store 2 code: wholesale_engb

So I get a fatal error when the following code is run:
// Initialize Magento
Mage::app( 'default' );

There ought to be an option to specify a non-default store code in the Mage Enabler settings page.

Cheers

Avatar

Richard Feraro UNITED STATES

September 1st, 2010 at 7:49 pm

You’re right. Temporarily, you may edit the code where the Mage::app() is declared. I’ll do an update for the plugin for that purpose πŸ™‚ Thanks for the feedback.

Avatar

Richard Feraro UNITED STATES

September 1st, 2010 at 8:04 pm

Are the following codes being used as Store View Codes?
private_nbno, private_engb, wholesale_nbno, wholesale_engb

Avatar

Christopher NORWAY

September 1st, 2010 at 8:30 pm

My bad, yes they are store view codes rather than the store codes

Avatar

Richard Feraro UNITED STATES

September 8th, 2010 at 4:45 pm

Update your Mage Enabler copy.

Avatar

John

September 4th, 2010 at 6:02 am

Hi Richard,

Very cool plugin, well done! This is potentially exactly what I need, in terms of building e-commerce into a WordPress instance. The only thing that I’m having difficulty with is syncronising the Magento database with the WorPress one. Correct me if I’m wrong, but in order for the plugin to allow a magento session to be authorised within WordPress, the user needs to have credentials in both databases?

Any tips on how to accomplish this automatically i.e when a client checks out in magento it populates the WordPress databse table too?

Thanks,
John

Avatar

Richard Feraro UNITED STATES

September 7th, 2010 at 5:17 pm

Hello John, here are my answers to your questions.

Correct me if I?m wrong, but in order for the plugin to allow a magento session to be authorised within WordPress, the user needs to have credentials in both databases

Nope. Whether both applications are using the same or different user credentials or none at all, the Mage Enabler can run the Mage object within WordPress. The account-related methods accessible via Mage object are just one the many functionality that can be extended by Mage Enabler within WordPress.

Any tips on how to accomplish this automatically i.e when a client checks out in magento it populates the WordPress database table too?

Mage object retrieves whatever is stored in the Magento DB so basically, if you create a new customer in Magento, it can be pulled using the Mage object like this post. It will require additional programming though since you need to detect if a new record has been added and use the built in functions of WordPress to save it in its respective tables.

Avatar

wp-popular.com » Blog Archive » Mage Enabler: A plugin to run Magento’s session within WordPress UNITED STATES

September 16th, 2010 at 6:32 am

[…] here to read the rest: Mage Enabler: A plugin to run Magento’s session within WordPress Tags: bridge, magento, […]

Avatar

Joshua UNITED STATES

September 16th, 2010 at 8:02 am

Question. How can i get Magento store products to display inside my WordPress post and pages with Mage Enabler? I want to have featured products show up in the main page of a customer wordpress site.

Avatar

morris UNITED STATES

September 16th, 2010 at 2:56 pm

Would anyone be so kind to share a demo or live site to get a feel of what to expect?
Thanks,
Morris

Avatar

Richard Feraro UNITED STATES

September 16th, 2010 at 10:36 pm

Hello morris,

Installing the plugin will not show any changes in your WordPress instance by default. It runs the Magento’s Mage object within WordPress which allows you to do these examples to your WordPress.

Avatar

bob UNITED STATES

September 25th, 2010 at 11:33 pm

i installed everything

now trying to valadate absolute url of Mage.php

on server it is in:

www/magentotest/app/Mage.php

I tried

www/magentotest/app/Mage.php

and

http://pro-tools-training.com/www/magentotest/app/Mage.php

did not work = Invalid URL

Avatar

Richard Feraro PHILIPPINES

September 26th, 2010 at 3:10 am

Hi Bob, I think there must be a forward slash at the beginning of the absolute URL. Also, start the url from the root it self. www is your webroot so it should begin from the home or root. It should look something like the one below:

/home/bob/www/magentotest/app/Mage.php

Avatar

Magento Wordpress Integration for multiple Websites via sub-directories. | molotov.bliss

September 30th, 2010 at 12:12 am

[…] plus to using the Mage-Enabler WordPress plugin is the ability to call on anything from Magento into WordPress. Some examples would be pulling in a […]

Avatar

George UNITED STATES

October 3rd, 2010 at 2:15 pm

Where can I see an example of a live site that is running this plug-in with Magento?

Avatar

Lance UNITED STATES

October 15th, 2010 at 6:43 am

I have enabled everything and tried to test if the user was logged in and display there name in the header. The first try it worked, but all of the sudden it stopped working. I am not getting any errors, it just does not think the user is logged in on the wordpress side. If i go into the store it knows I am logged in.

Any ideas what might be causing this? Thanks!

Avatar

Richard Feraro UNITED STATES

October 15th, 2010 at 7:48 pm

Try using the following code in one of your theme files. If Mage Enabler is working, you should see Mage and Varien in the array output.

echo "<pre>";
print_r(get_declared_classes());
echo "</pre>";

Also, set your error_reporting() to E_ALL to display any possible error in your test server.

Avatar

George UNITED STATES

October 25th, 2010 at 4:48 pm

I am currently using Magento but I hate the way it looks and it seems much more difficult to design a theme for it than it does WordPress. I am very interested to see your plug-in in action. Can you point me to some live sites are using it?

Thanks.

Avatar

George UNITED STATES

October 26th, 2010 at 6:08 am

Where can I see some live sites that are using the “Mage Enabler” plugin?

Avatar

Richard Feraro PHILIPPINES

October 26th, 2010 at 11:57 am

George, I moved your comments here because you’ve been posting question irrelevant to the thread. Your question has already been answered here.

Please keep my blog clean by sticking to the topic.

Avatar

George UNITED STATES

October 27th, 2010 at 5:18 pm

Sorry for posting in the wrong place.

I checked your link but surprisingly after three months there are still no links to any sites using the Mage Enabler.

Do you have a test site up running?

I am new to WordPress and I am just trying to see what the plug-in can do before I invest a bunch of time learning something new.

Thanks.

Avatar

Richard Feraro UNITED STATES

October 28th, 2010 at 6:09 pm

The test site is still in progress since I’m updating the plugin at the moment for more features such as shortcodes and stuff that pulls block from Magento. I do hope I can release it this November.

Avatar

May PHILIPPINES

November 17th, 2010 at 11:41 am

Hi, I have read your posts (from the first one), using magento with wordpress with hard code examples and I was amazed with the idea so i followed the links which brought me to your latest post, I was wondering if using the plugin you made, I could, integrate wordpress 3.0.1 with Magento Professional Edition platform and would it be in conflict if I add Quickbook plugins/ IMS for magento as well?

I hope this idea would suit with what I need.

Thanks, real nice plugin..

Avatar

Richard Feraro

November 17th, 2010 at 12:08 pm

Hi May,

There shouldn’t be any conflict with other plugins since you’ll be using Mage object to access Magento’s methods, be it in WordPress or other external PHP-based application.

Thanks πŸ™‚

Avatar

Salty UNITED STATES

November 17th, 2010 at 12:12 pm

I followed the instructions and getting:

Parse error: syntax error, unexpected T_STRING in /home/egypt/public_html/wp-login.php on line 563

Any ideas? =(

Avatar

Richard Feraro

November 17th, 2010 at 12:21 pm

Post the code you added in wp-login.php at line 563 here.

Avatar

Salty UNITED STATES

November 17th, 2010 at 12:33 pm

This is when trying to login/logout

Avatar

Salty UNITED STATES

November 17th, 2010 at 12:35 pm

560 $reauth = empty($_REQUEST[‘reauth’]) ? false : true;
561
562 // If the user was redirected to a secure login form from a non-secure admin 563 page, and secure login is required but secure admin
564 is not, then don’t use a secure

Avatar

Salty UNITED STATES

November 17th, 2010 at 12:36 pm

figured it out needed //

=)

Avatar

Richard Feraro UNITED STATES

November 17th, 2010 at 4:12 pm

Yeah, saw it too. Multi-line comments requires // per line or use /**/ instead πŸ™‚

Avatar

Bryan UNITED STATES

December 24th, 2010 at 8:51 am

Richard,
I am using a magento site now and the seo is kind of weak. I want to convert my site to a wordpress site (for seo purposes), then integrate magento as you have. I just wanted to understand more of how wordpress controls the frontend and magento controls the backend. As well as make sure my h1 and h2 tags are above line 233 (current magento site).

Are there any sample sites that are using your integration that I can inspect the source?

thanks!

Avatar

Richard Feraro PHILIPPINES

December 27th, 2010 at 7:04 am

Hi Bryan, most of the users of the plugin I made doesn’t really share the url of the site where they use it. πŸ™‚

Avatar

Bryan UNITED STATES

December 29th, 2010 at 1:39 am

That’s unfortunate Richard,
If I get this working correctly with my site I’ll be happy to share. Do you know of any sites that use it?
Or do you have a test site out there?

thanks.

Avatar

Richard Feraro PHILIPPINES

December 29th, 2010 at 2:37 am

Avatar

Bryan UNITED STATES

December 30th, 2010 at 12:28 am

thanks for the link that site looks good, but does it use WP? I don’t see it anywhere in the source.

Also I have the Mage enabler set up on my test site but when logged in I still receive ‘Hello Guest!’ on the index.

http://freakinadorable.com/wordpress/

Avatar

Richard Feraro PHILIPPINES

December 30th, 2010 at 3:14 am

1. Did you try logging in to WordPress using a subscriber account?
2. Did you check if there’s a frontend cookie being generated?
3. What have you done so far?

Avatar

Richard Feraro PHILIPPINES

December 30th, 2010 at 3:19 am

I also visited the URL below to register a customer account and was greeted with a 404 error. Mage Enabler requires a working Magento setup. You need a Magento customer account and a WordPress subscriber account with the same credentials for it to work.

https://freakinadorable.com/magento/index.php/customer/account/login/

Avatar

Bryan UNITED STATES

December 30th, 2010 at 5:13 am

Yeah for some reason it is redirecting to https. Magento is working under that directory if you use http://freakinadorable.com/magento/ . I wonder if I set it up incorrectly in the first couple install stages.

the questions above:
1. I did create an account using subscriber WP/magento (same credentials)
2. When using firebug I could not see any cookies being created
3. I went through the setup instructions, clean install of both magento and WP, for your page plugin.

I bet it has something to do with that redirect to https though…

Avatar

Richard Feraro UNITED STATES

December 30th, 2010 at 5:04 pm

If you can’t see any cookie being generated (make sure you have Firecookie added in your Firebug tab), add the code below at the very top of the files where you added the Magento scripts within your WP instance. This will display the errors you might be having within the code. Make sure to remove this code once your site is in production stage.

error_reporting(E_ALL);

Avatar

Wes Davis AUSTRALIA

January 5th, 2011 at 8:29 am

Hi Richard, When you say that most people don’t have the Magento & WordPress running on the same URL – is there a reason for that?

Would it be workable to say have WP run on http://domain.com and Magento running on http://store.domain.com – in other words on a subdomain?

Cheers, Wes

Avatar

Richard Feraro PHILIPPINES

January 5th, 2011 at 12:30 pm

Hi Wes, it’s possible to do it using a subdomain πŸ™‚

Avatar

Wes Davis AUSTRALIA

January 5th, 2011 at 6:09 pm

Thanks mate πŸ™‚

Avatar

Jeroen NETHERLANDS

January 6th, 2011 at 10:17 pm

Hi Richard, great plugin.. got a question. I’m building a new wordpress site right now and want include parts of a magento shop wich is hosted on another server. Is this possible too?

Avatar

Richard Feraro UNITED STATES

January 6th, 2011 at 10:30 pm

Hi Jeroen πŸ™‚

If you’re going to use Mage Enabler, its primary requirement is the absolute local path to your Mage.php. Consequently, you can’t unless you have administrator access to both hosts which will allow you to do some serious symbolic linking and still you are confined to have the two host accessing each other locally.

Avatar

Jeroen NETHERLANDS

January 7th, 2011 at 3:09 am

Ok, clear.. so it’s probably not going to work. The WordPress site is mine.. the Magento store is from a company that sells some of my goods, I wanted to integrate them in my own site. I’m know with the owners of the store though.

Avatar

Dave UNITED STATES

January 10th, 2011 at 1:34 am

Id like to embed my magento shopping area into a wordpress page. Then add the shopping card module into a widget area in wordpress. Not sure where to start.

Avatar

Richard Feraro PHILIPPINES

January 10th, 2011 at 1:56 am

Follow the post.

Avatar

ewoud NETHERLANDS

January 18th, 2011 at 7:04 pm

Hi Richard,
I was how the notification from the payment processor is handled when you try to keep the whole shopping experience within a wordpress environment.
example: the customer selects a product, goes to the payment system, completes payment and then when the payment is successful the payment script does a callback to finalize the order. ( i.e. http://www.example.com/index.php/magentodir/msp/mspPayment/notification/ )

what do you have to do to handle this within the wordpress environment, so the customer never sees the magento backend?

Avatar

Richard Feraro PHILIPPINES

January 18th, 2011 at 10:14 pm

I believe that every payment facility like PayPal and similar sites allows the administrator to provide a Return URL parameter by which the confirmation will be sent. You just have to redirect it to your WordPress page handling the confirmation.

Avatar

Daniele ITALY

February 4th, 2011 at 11:08 pm

Hi there!
This plugin could really solve some of my problems πŸ™‚
Btw, I’ve installed it correctly (I think) on my localhost and I see the cookie, but when I login I still see the “welcome guest” message.
I’ve a question: what u mean with same credentials? In Magento I login with email and password, but in WordPress I login with username (not email).
Second question: can I contact you via private email in case I need some paid works?
Let me know. πŸ™‚
Thanks!
d

Avatar

Richard Feraro PHILIPPINES

February 6th, 2011 at 7:26 pm

Hi Daniele!

The same credentials that I was referring to the post was the customer account in Magento and subscriber account in WordPress πŸ™‚

Avatar

Very useful Wordpress plugin to connect with Magento UNITED STATES

February 25th, 2011 at 12:30 pm

[…] Copy the necessary codes (lines 16-18 and 22-40) to make it similar below: view sourceprint? […]

Avatar

Lina Maria CANADA

March 3rd, 2011 at 4:25 am

Hi Richard

Thanks for your plugin, I’m pretty sure that it’s going to help me in my job

I have a question, in setting when you ask for Absolute URL of the file, is it possible to have magento and wp in different servers ? cause your example (/home//public_html/app/Mage.php) doesn’t clarify my doubt

Thanks

Avatar

Richard Feraro UNITED STATES

March 4th, 2011 at 12:43 am

Hi Lina,

It has to be on the same server. What do you plan to use as an absolute path to Mage.php?

Regards

Avatar

Lina Maria CANADA

March 4th, 2011 at 4:16 am

Thanks Richard but my site and my shopping are in differents servers, so it’s not working for me

Avatar

Richard Feraro

March 4th, 2011 at 5:09 am

Yeah, it won’t work that way.

Avatar

Matt Brown UNITED STATES

April 30th, 2011 at 7:03 am

Hi Richard. Thanks for building this plugin, it’s very helpful!

It loads Magento the way it should, but I’m having trouble getting the sessions (WP and Magento) to work together. I can insert the following code into a php document outside WordPress and it will report accurate numbers regarding items in my cart, but as soon as I drop it into my WordPress sidebar, it says I have 0 items in my cart.

Thoughts?

Code:

‘frontend’));
$cart = Mage::helper(‘checkout/cart’)->getCart()->getItemsCount();

echo ‘Items in your cart: ‘ . $cart . “”;

?>

Avatar

Richard Feraro UNITED STATES

April 30th, 2011 at 10:47 am

Hi Matt πŸ™‚

Did you place the code below in your template’s index.php, just above the get_header();?

if(class_exists('Mage')){
    Mage::getSingleton('core/session', array('name' => 'frontend'));
 }

Avatar

Rait ESTONIA

May 2nd, 2011 at 2:20 pm

Hi Richard,

once again, a very cool and useful plugin. However, I seem to be having a problem that has been addressed here before, only I’m not able to resolve it with sugestions offered.

I’ve taken care of the function collision problem as instructed. My Mage.php is recognized in the config of the plugin. I’ve added the example code into my WP template header, to make sure it’s loaded on every page. The frontend cookie is being generated just fine. I have matching accounts of WP subscriber and Magento customer.

But in the end, after logging in via WP, I’m still being greeted as a “Guest” Also, if I get an active Magento session cookie by logging into WP. If I visit my Magento page which is in a subfolder, theoretically I should be recognized as logged in as well? At the moment, it’s not happening.

Avatar

Richard Feraro UNITED STATES

May 3rd, 2011 at 9:58 am

My Mage.php is recognized in the config of the plugin. I’ve added the example code into my WP template header, to make sure it’s loaded on every page.

You should put it in index.php of you template file, just above the get_header(); call.

If I visit my Magento page which is in a subfolder, theoretically I should be recognized as logged in as well? At the moment, it’s not happening.

It doesn’t follow. You should check your Magento cookie path. If the path is inside that subdirectory where your Magento is, then the parent directory which is your WP instance doesn’t share the same session. If it’s the other way around, meaning your Magento serves as your parent directory and WP is in a subdirectory, then it will work the way you mention.

How about passing the PHPSESSID from WP (your parent directory) to Magento (subdirectory)? I maybe be unsecured though.

Avatar

Matt Brown UNITED STATES

May 3rd, 2011 at 12:06 am

Yes, I’ve tried placing it there. I’ve also experimented putting it in my page.php file above the get_header() call, but still no luck.

Avatar

Richard Feraro UNITED STATES

May 3rd, 2011 at 9:59 am

You should only have one (1) instance of the code below:
if(class_exists('Mage')){
Mage::getSingleton('core/session', array('name' => 'frontend'));
}

Avatar

Matt Brown UNITED STATES

May 3rd, 2011 at 3:27 am

Including the core/session singleton in the template index.php file doesn’t work, but I can get the Magento session to load in WordPress if I require and initialize Magento in the root index.php file (before the WordPress framework loads). This is very strange, but at least I have a band-aid fix for now. I’ll have to keep adding that code every time I update WordPress, which is very inefficient.

Any ideas as to how I can add Magento before WordPress Loads without doing it the way I’ve described?

Avatar

Richard Feraro UNITED STATES

May 3rd, 2011 at 10:05 am

That’s weird. There’s a big chance that you’ll get a ‘Cannot send header information…’ error with that setup. The call for core/session for frontend should only be done once in the template’s index.php. Try removing your ‘band-aid’ fix and check if there’s ‘Mage’ class being instantiated. You can do that by adding the code below to your template file WITHOUT your fix.

<?php print_r(get_declared_classes()); ?>

You should see Mage and Varien_Autoload if your plugin setup is correct.

Avatar

Matt Brown UNITED STATES

May 3rd, 2011 at 11:00 pm

I can confirm that both Mage and Varien_Autoload are present just using Mage Enabler, but it still will not pass the session information unless I include Magento before WordPress is initialized (band-aid).

I’ve been experimenting putting the Mage launch code at different points in my wp-settings.php file. IT appears that the code works until line 190 (a foreach loop that includes the plugins). This leads me to believe that I have a conflicting plugin. I’ll try deactivating plugins one-by-one to see if I can find the culprit.

Thanks for your help!

Avatar

Matt Brown UNITED STATES

May 3rd, 2011 at 11:13 pm

I can confirm that the issue I’m experiencing was a plugin conflict. It appears that WP E-Commerce (our existing cart we’re trying to move away from) is clashing with the Magento code. Thanks again for your help Richard.

Avatar

Richard Feraro UNITED STATES

May 4th, 2011 at 8:42 am

Hmm, interesting what could be the cause. I might have to check on that to make sure Mage Enabler compatible with any setup.

Avatar

rishad INDIA

June 8th, 2011 at 9:54 pm

Hi,

We tried to implement this module in a buddypress+magento site (Followed all steps given in documents). But didn’t see any result yet. Do we need any modification in order to use this with a buddypress installation? please help us as

Regards,
Rishad.

Avatar

Richard Feraro PHILIPPINES

June 24th, 2011 at 12:23 am

The plugin is made specifically for WordPress setup

Avatar

juan SPAIN

June 30th, 2011 at 1:08 am

hi,good work, i have a answer, How i show in a post of wordpress a product of magento? i cant see how,maybe i need sleep……

Avatar

Stu UNITED STATES

July 1st, 2011 at 3:23 am

Great work Richard. I’m using this the way it was meant to… WordPress -> Magento and back. looking forward to giving this a try, and hopefully using WP as a fronted for the whole Magento system.

Thanks again!
Stu

Avatar

Stu UNITED STATES

July 1st, 2011 at 5:31 am

Richard,

I’ve read through all the comments, and do understand about putting the

if(class_exists(‘Mage’)){
Mage::getSingleton(‘core/session’, array(‘name’ => ‘frontend’));
}

code in the index.php of the theme. Unfortunately, the site I am working on NEVER hits that page, so it won’t generate the cookie.

I placed that code block above the get_header() in the page.php file (the default page template for the site). I do see a ‘frontend’ cookie generated, albeit with a period in front of the domain, ie:

.www.bsatest.com

I have created a Magento user with the same credentials as a WP user.

Then Mage Enabler is installed and seems to be working.

I’m not getting the correct username after logging in, and am still seeing Welcome Guest.

Any help would be appreciated!

Stu

Avatar

Stu UNITED STATES

July 1st, 2011 at 6:18 am

I’m also seeing this one now…

Fatal error: Uncaught exception ‘Zend_Controller_Response_Exception’ with message ‘Cannot send headers; headers already sent….

Avatar

Eddie UNITED STATES

July 19th, 2011 at 9:50 pm

Would you be willing to develop a Magento Enabler for Drupal?

Avatar

Eddie BRAZIL

August 9th, 2011 at 9:50 pm

Richard, I’m trying to figure out if your solution is the best one in my case. I want to be able to use any WP plugin and upgrade WP as needed. I also want to be able to upgrade Magento normally. The only thing I need is for the user to not lose the session when moving between magento and wordpress. I dont even really need to have WP use magento’s theme (I will create a WP theme that is similar enough).

Based on what I read, I take that this plugin IS what I need… Would you please confirm that, based on what my needs are?

TIA

Avatar

Richard Feraro PHILIPPINES

August 13th, 2011 at 1:37 pm

Yes, the approach would be the same as written in the article πŸ™‚

Avatar

Ari SPAIN

August 10th, 2011 at 7:39 pm

@Eddie, with the code supplied it shouldn’t be too difficult to do a Drupal Enabler for Magento. Ask if you need further help.

Avatar

Ari SPAIN

August 10th, 2011 at 7:54 pm

@Matt Brown

If you want that setup to work, you might consider modifying the ‘Cookie path’ directive in your Magento Admin. Check it out:

http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/system_config/edit/web#session_cookie_management_field_descriptions

Cheers.

Avatar

Mage Enabler review, discussions, does it work, and ratings on Loadwp.com | Loadwp.com NETHERLANDS

August 17th, 2011 at 10:13 am

[…] 1.1.1 = * Fixed fatal error during xmlrpc calls see comment #417. Thanks mik for the […]

Avatar

Dave IRELAND

August 17th, 2011 at 7:34 pm

Hi, great plugin, thanks.

I can’t seem to get the login working.
If I have an account setup in magento i.e.
usr: dave@email.com
pass: xxxx

When I try to login to wordpress it doesn’t work.

Also when I login to magento and go to the blog it still says welcome guest.

I edited the functions file, the user file and the wp-login file as above

Am I missing something?

Avatar

Sebastian TΓ€nzer GERMANY

August 17th, 2011 at 9:19 pm

We ran into problems using the MageEnabler plugin to retrieve session data, in our case the cart data when a user is not logged in. This does NOT work using MageEnabler (or at least we did something wrong)

In case you want to display the cart count outside of Magento we did this like Matt Brown mentioned earlier.

We disabled the MageEnabler plugin and manually loaded the Magento stuff in our WordPress index.php:

‘frontend’));
$session = Mage::getSingleton(‘checkout/session’);

?>

This basically does the same as MageEnabler.

In your WordPress template get the stuff you want:

getCart()->getItemsCount();
}
?>

This is with WP 3.1.4 and Magento 1.5.1

Cheers,
Sebastian

Avatar

Sebastian TΓ€nzer GERMANY

August 17th, 2011 at 9:20 pm

My PHP code got messed up. It should read:

require_once(“/absolutePathToMagePhp/app/Mage.php”);
umask(0);
Mage::app();
Mage::getSingleton(‘core/session’, array(‘name’=>’frontend’));
$session = Mage::getSingleton(‘checkout/session’);

and

if(class_exists(‘Mage’)){
# this gets the items count in your cart
$cart = Mage::helper(‘checkout/cart’)->getCart()->getItemsCount();
}

Avatar

Paul UNITED STATES

August 17th, 2011 at 10:08 pm

Hi Richard! I really appreciate your work!
I’ve been trying to make your plugin work on WP 3.2.1 and Magento 1.5.1 but without success. I still don’t get the frontend cookie.

I have my WP installed in htdocs/wordpress/ and magento in htdocs/wordpress/magento

If you have time, can you please write the steps we have to do (what files we have to modify and the code) in order to work. You mentioned that some files don’t have to be modified if you install the plugin, but is still confusing.

I’d really appreciate you help!
Thanks!

Avatar

Dave IRELAND

August 18th, 2011 at 12:14 am

Just to add to my message. Would it be a cache thing? I’m running both programs locally with a blog folder inside the main magento folder.
Should I set the cache system in the configuration in MAgento somehow?

Avatar

Paul

August 18th, 2011 at 6:13 pm

Hi Richard!
I really can’t get the cookie “frontend” show up. I’m using Magento 1.5.1

Avatar

Fede UNITED STATES

August 25th, 2011 at 2:54 pm

I entered the URL of mage.php and I go this error:

Fatal error: Cannot redeclare __() (previously declared in /home/italian6/public_html/blogs/wp-includes/l10n.php:96) in /home/italian6/public_html/eStore/app/code/core/Mage/Core/functions.php on line 96

Avatar

Mathew Beane UNITED STATES

September 29th, 2011 at 9:38 pm

I have a project in development, that has a wordpress site on one domain and a magento site on another domain. When transfering the session over, I append the SID to the URL, and it almost works.

By almost, I mean this:
1) You can add items to cart in wordpress, the cookie sessionID stays the same throughout this.
2) I send the user to the magento site, via a header location, or presenting a link for them to click, with the session ID at the end of the url, such as: http://magentositehere.com/checkout/cart?SID=b72k45bsh1igsvkojva4o33d27
3) The cart appears empty, and if you pay attention to the cookie id, it has switched at this point.
4) Refresh the page, by pasting the URL in, and the cart works properly, maintaining the cookie session ID
5) Now, if you go back to the wordpress site, and add differnt items to the cart, and go back to the magento site, the cart and cookie session ID work as you would expect.

I can duplicate the issue by purging the cookies in the browser cache. It starts the whole thing over, with the cart appearing empty.

Have you seen this? I suspect rewrite rules, but cant find the issue yet. Any help would be very appreciated.

Avatar

scott godin UNITED STATES

October 25th, 2011 at 3:53 am

we have an existing magento site, and want to create a new storefront for it with different theme, sharing some products but in different categories, and with additional products unique to this store.

we want to template the front end more like a cms with portfolio etc, and a single link in the wp site to the shop section.

not quite sure of the question to ask, but generally my query is how would you use this plugin to access mystore2 inside magento instead of the main store?

Avatar

Richard Feraro

October 26th, 2011 at 8:31 pm

You may use the setStore method.

Avatar

scott godin UNITED STATES

November 3rd, 2011 at 5:55 am

would you be able to contact me directly via email? I’m having an issue with the wordpress + magento install where enabling the plugin immediately causes a cascade of errata in the footer section of the site, and it’s a bit large to be pasting in here.

wordpress is installed in the docroot, magento is installed as a 2nd storefront in a shop/ subdomain (shop.mysite.com)

as soon as mage-enabler was enabled and configured, the footers disappeared. I had to turn on wp_debug to see what was going on, and it was a bit more than I had expected.

Avatar

Rahn ISRAEL

January 19th, 2012 at 5:33 am

I did What the article asks, and nothing changes.
Is my magento installed on port 81 presents a problem?

Avatar

Richard Feraro

January 26th, 2012 at 2:54 pm

It should not be an issue.

Avatar

Rahn ISRAEL

January 21st, 2012 at 5:51 am

Hello Richard, I wrote posted to you already. I followed your instructions in this article, everything seems fine, but the welcome guest does not appear on the homepage.

Avatar

Richard Feraro

January 26th, 2012 at 2:55 pm

What’s the cookie domain?

Avatar

Teemu RΓ€sΓ€nen FINLAND

February 24th, 2012 at 10:44 pm

Thanks a million! works like a charm and totally saved my day.

Thanks again!

-Teemu

Avatar

andreina JAPAN

March 27th, 2012 at 6:00 pm

hola termine mi tienda magento ahora estoy intentando colocarle en wordpress solo que esta corriendo desde xamppin , mi pregunta es si con tu plugin yo prodria integrarla a wordpress

Avatar

Richard Feraro

March 28th, 2012 at 10:28 am

Can you translate it to English please? I tried to use the Google Translate but I still can’t understand your inquiry.

Avatar

Limar UNITED STATES

March 31st, 2012 at 7:59 am

Hello,

I have had a WP blog for some time now. I use it more like a website than a blog.

I want to put my magento product into my wordpress page. Will this plugin do this?

I want all the checkout and everything to be done in a wordpress page. All I want from magento is the functionality of it’s e-commerce onto my wordpress website.

– Limar

Avatar

Richard Feraro

March 31st, 2012 at 10:02 am

Yes it can, but you’ll need to do the scripting after installation of the plugin. You can check the post and comments here to see how to apply it.

Avatar

limar UNITED STATES

March 31st, 2012 at 11:27 am

Hello Richard!

Thank you for your prompt response!

Do you by any chance offer a service to have this done on my website? I have only one product with different variations that I would like to add onto 1 wordpress page.

Evidently what I want to do is just be able to ‘add to cart’, when added then you get redirected to checkout within a wordpress page.

Your help will greatly be appreciated as you sound like an experienced programmer!

Avatar

Wallace Crain UNITED STATES

April 19th, 2012 at 3:12 am

Hi Richard – is it possible to inherit the object and variable scope for phtml files referenced from within WP?

(e.g., ‘$_cartQty = $this->getSummaryCount()’ in the magento cart phtml)

I can call phtml files (static) and can get the magento cart/session data separately, but would like to avoid recreating the phtml from scratch (and maintaining two identical header pieces) in order to display the same ‘my cart’ piece in both the magento and WP headers.

Thanks!
-Wallace

Avatar

Richard Feraro

April 19th, 2012 at 5:30 am

I haven’t tried it yet. Can you elaborate your example?

Thanks!

Avatar

Wallace Crain UNITED STATES

April 19th, 2012 at 2:40 pm

Hey Richard thanks for the quick response!

Sure – so trying to re-use same phtml files from magento header in WP and I can get a ‘myaccount’ phtml from magento to show in WP with variables like username carried over:

Mage::getSingleton(‘core/session’, array(‘name’=>’frontend’));
$layout = Mage::getSingleton(‘core/layout’);
$myaccountBlock = $layout->createBlock(‘page/html_header’)->setTemplate(‘page/html/myaccount.phtml’)->toHtml();

echo($myaccountBlock);

..but when doing the same with the cart phtml the quantity is always ‘0’ on the WP side:

Mage::getSingleton(‘checkout/cart’)->getItems();
$carttest = Mage::getSingleton(‘core/cart’);

$mycartBlock = $layout->createBlock(‘page/html_header’)->setTemplate(‘checkout/cart/cartheader.phtml’)->toHtml();

echo($mycartBlock);

Am I missing a getSingleton or helper call to get the cart quantity to show on the WP side?

Let me know if that makes sense and thanks again!
-Wallace

Avatar

Wallace Crain UNITED STATES

April 21st, 2012 at 2:14 am

Hey Richard – got it worked out (pbkac):

$mycartBlock = $app->getLayout()->getBlockSingleton(‘checkout/cart_sidebar’)->setTemplate(“checkout/cart/cartheader.phtml”)->toHtml();

Thanks again though!
-Wallace

Avatar

Richard Feraro

April 21st, 2012 at 7:23 pm

Great!

Avatar

Michael Ramin ITALY

June 14th, 2012 at 5:25 pm

Good job man!

Avatar

Antonello Palumbo ITALY

June 19th, 2012 at 10:30 pm

Hello Richard, I installed your plugin and followed your guide step by step. I find the cookie “frontend” but if I try to login the message is always “Welcome Guest.” Username (email) and password are the same on wordpress and magento. I use WP 3.4 and Magento 1.7 . Thanks for answer

Avatar

Antonello Palumbo ITALY

June 19th, 2012 at 10:59 pm

I resolved: add this line $ session-> setCustomerAsLoggedIn ($ session-> GetCustomer ()); in user.php after $ session = Mage :: getSingleton (‘customer / session’). Why not open the session on Magento?

Avatar

Keerthi INDIA

August 29th, 2012 at 6:49 pm

I have installed Mage Enabler, my project deployment is like Magento is installed in xx.yy.com and wordpress in zz.yy.com, currently in this setup when i try to access the magento session im not able to get the customer session value on wordpress.

I can see only Welcome Guest

But when i deploy the project like magento on yy.com and wordpress on yy.com/wordpress . then i’m successfully able to get the session value.

I can see message as Welcome User[user of magento]

Can you explain whether in the first setup will the mage enabler work if so please let me know what should alter

Avatar

Richard Feraro PHILIPPINES

August 29th, 2012 at 7:04 pm

Hello Keerthi,

The answer to your question is the availability of the Magento cookie. The reason why the setup where Magento is installed in yy.com works because the Magento cookie is available to ALL directories under yy.com (which includes zz.yy.com and yy.com/wordpress) where as when it is installed in xx.yy.com, it is only available to those directories within xx.yy.com. Check the cookie domain and path in the admin settings for more info.

Thanks for dropping by.

Avatar

Keerthi INDIA

August 31st, 2012 at 2:59 pm

Thanks Richard for the reply, Now my doubt is clear. If you could guide me on what type of settings if i could make change in the cookie domain & path, it would be helpful for me.

I tried on those settings i’m quiet unsuccessful.

Avatar

sanjay INDIA

October 4th, 2012 at 10:13 pm

hi Richard,

first of all this is an amazing plugin πŸ™‚ thanks for creating such a great thing.

here i want to integrate wordpress with the magento (i installed the magento as a subdirectory inside the wordpress folder). i have followed all the instructions you mentioned in the posts. i can see frontend cookie. but my problem is the site is showing only “welcome guest” note (it doesnt change when i logged in or not). i have used same username and password for the admin side of the wordpress as well as magento. please let me know what is my issue.

(also i have made the changes in the index.php, wp-login.php and the users.php).

Avatar

Richard Feraro

October 5th, 2012 at 11:31 am

Hello Sanjay,

You need to make sure that the Magento cookie domain path also includes the location of your WordPress installation. Check my reply to Keerthi above.

Regards,

Avatar

sanjay INDIA

October 5th, 2012 at 3:32 pm

Thanks for your response Richard,

i am just a newcomer in this field. so could you please guide me where i can find the Magento cookie domain path ? do you mean the absolute URL setting in the plugin’s admin side? should i need to edit any other files?

please advise me..

Avatar

AUS-IP AUSTRALIA

December 19th, 2012 at 5:17 am

We are getting an Invalid URL error when entering the Mage.php path. We have entered the full & correct path, taking note of case sensitivity, yet we are still getting this error

Any ideas. It is a Plesk server managed by ourselves.

Avatar

Richard Feraro

January 3rd, 2013 at 12:31 pm

Is it in the same machine as your WP instance?

Avatar

nauka slowek angielski POLAND

March 25th, 2014 at 7:09 pm

When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I
get four emails with the same comment. Is there any way you can
remove me from that service? Many thanks!

Comment Form

About my blog

This blog is targeted towards all levels of developers and also designers. Various topics are discussed such as Magento, PHP & MySQL, jQuery, WordPress, CSS and HTML.

Booking.com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 5,242 other subscribers

WordPress + Magento

Recent Trackbacks

Archives

Disclaimer

All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or my mom.