Tutorials for Magento and Joomla! - Yireo

Switch between Magento theme and Joomla! template

In the past we've been asked if MageBridge (with Joomla!) could be used for Magento catalog-pages, while the original Magento theme (without Joomla! template) was used when a customer entered the checkout. Back then, we said this was not possible, but actually we made a mistake there: MageBridge already contains all the tooling, it just depends how you use these tools.

Why use a separate Magento theme with MageBridge?

With MageBridge, Magento is integrated in Joomla! and the Magento Default Theme is also combined together with the Joomla! template. It's a quick and dirty solution to give Magento-specific structures like product-pages and shopping-carts the right styling, while still giving you all the flexibility to change this with Joomla! styling.

But some people want to use this flexibility of Joomla! when it comes to catalog-pages, but refer back to the original Magento stand-alone situation at certain points: For instance, the Magento checkout is filled with ProtoType JavaScript, which is harder to combine with Joomla! extensions. If you could use the stand-alone Magento theme just for the checkout, this problem would be solved easily.

Also, some shop-owners already have a full-blown Magento theme which works perfectly during the checkout, while only on the catalog-pages Joomla! is used to enrich the content. There are many reasons to use the stand-alone Magento theme while still using MageBridge. (But we actually recommend to make full use of MageBridge once you start using it.)

MageBridge modules can show any Magento block

Now the trick is to display the entire Magento site ... within Joomla but without all of the Joomla! templating. The trick is made possible with the MageBridge Custom Block module. It is capable of displaying any Magento block, for instance the shopping cart, a sidecolumn named left or the whole content-area of Magento (which equals the Joomla! component-area).

Now the Magento theme is built up using blocks, but all blocks are part of one major block named root, which equals the HTML-document. Even this block could be displayed using the MageBridge Custom Block module, effectively wrapping Magento into Joomla! without using extra Joomla! logic.

mb_rootmodule

The screenshot above shows a Joomla! module of the type MageBridge Custom Block, configured to display the Magento block root on the Joomla! module position root.

Putting MageBridge logic to use within the Joomla! template

Now, the MageBridge extension contains a MageBridgeTemplateHelper class which helps you adding all kind of Magento logic to your Joomla! template. For instance, you can determine whether the current MageBridge page is displaying the Magento checkout.

$mb = new MageBridgeTemplateHelper();
if($mb->isCheckoutPage()) { ... }

This will also include the shopping cart page, which we can exclude by enhancing the code a bit:

$mb = new MageBridgeTemplateHelper();
if(!$mb->isCartPage() && $mb->isCheckoutPage()) {

Display the root-block during the checkout

Now we can put all this logic together: Within the Joomla! template a regular Joomla! templating structure is defined, which is fine for all pages except the Magento checkout-pages. For the Magento checkout we want to get rid of all the Joomla!-extensions and only display the Magento root-block. This root-block is assigned to the Joomla! module-position root through the MageBridge Custom Block module.

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
 
// Checkout page
$mb = new MageBridgeTemplateHelper();
if(!$mb->isCartPage() && $mb->isCheckoutPage()) { ?>
<jdoc:include type="modules" name="root" style="raw" />
<?php } else {
 
// All other pages
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
... the rest of your Joomla! template

Conclusion

This example shows you how much you can do with MageBridge - it is ment as an experiment and should not be used by MageBridge beginners. However it might serve a practical use for those who need it. By applying the right knowledge you can get a lot-of-things done.

Created on Tuesday, 23 March 2010
Modified on Thursday, 25 March 2010

About Yireo

Yireo tries to help webdevelopers build successful Joomla! and Magento sites.

More about Yireo