Getting started with MageBridge - Yireo

Reusing MageBridge parameters in Joomla! extensions

Joomla! offers an architecture of elements (JElements), which allow you to define form-fields to be used in XML-files. Joomla! offers form-fields like a category-dropdown or a modalbox with article-selection. MageBridge is using the same architecture to add its own set of elements to be used by any third party developer.

XML parameters

When you build your extension (whether it be a component, module or plugin) you might want to reuse some of the logic of MageBridge. For instance, if you want to easily configure a product ID for your own extension, a modal popup box to select the Magento product (as offered by MageBridge) is easier to use than a plain inputfield.

Within the XML installation-file of your extension you can define parameters, and the parameter-types can be extended with MageBridge parameters. These parameters can then be defined by the administrator, and used in the logic of your extension, for instance to link something to a Magento product-page.

MageBridge parameter-types

The following parameter-types are offered by MageBridge:

  • product: A modal popup for selecting Magento catalog products
  • category: A modal popup for selecting Magento catalog products
  • customer: A modal popup for selecting Magento catalog products
  • customergroup: A dropdown for Magento Customer Groups
  • website: A dropdown for Magento Websites
  • storegroup: A dropdown for Magento Store Groups of the current Website
  • storeview: A dropdown for Magento Store Views of the current Website
  • store: A hierarchical dropdown of Magento Store Groups and Store Views
These parameter-types are defined in the directory administrator/components/com_magebridge/elements. There are more types then listed above, but the other types are probably only useful for the MageBridge Configuration.

API widgets

These parameter-types (or elements) are - within the MageBridge documentation - actually referred to as API Widgets. The reason for this is that the elements behave differently if the bridge is online or offline. If the bridge is online, the API is used to fetch information from Magento and use it to build some kind of input-field. But if the bridge is offline, the plaintext value is displayed in a regular input-field. This gives you the ability to modify the data, even when the bridge is offline.

Adding the parameter-types to your own XML

The elements can be added to your own XML-definition by including the path to your parameters section:

<params addpath="/administrator/components/com_magebridge/elements">

You can add only one path to a parameter-section. This is a limitation of the current Joomla! version. However, you can define multiple parameter-sections in your extension.

Adding a Magento product

By using the product-type you can add a modalbox that allows you to easily select a Magento product in a popup window. With the following XML-tag this can be accomplished. The type is always set to product, but the name and label can be anything you want.

<param name="myproduct" type="product" default="" label="My Product" />

This will by default return the product URL-key of the product that you select in the modalbox. If you want to return the product ID instead, you would set the return-value to id:

<param name="myproduct" type="product" return="id" default="" label="My Product" />

You can also fetch the product SKU instead:

<param name="myproduct" type="product" return="sku" default="" label="My Product" />

Using the Magento product

Now that you have the URL-key, ID or SKU of the Magento product, you can reuse it in your application. Follow the Joomla! documentation (see link below) to see how to fetch the parameters. Once you've done that you have the value of the URL-key, ID or SKU inside your own extension, so the next question would be how to use it.

The URL-key can be used to construct a simple link to a Magento product-page:

$link = 'index.php?option=com_magebridge&view=root&request='.$url_key;
$link = JRoute::_($link);

The same counts for the Magento product ID. It is used in various Magento URLs, but it is also used to add a Magento product to the shopping cart:

$request = 'checkout/cart/add/product/'.(int)$product_id;
$link = 'index.php?option=com_magebridge&view=root&request='.$request;
$link = JRoute::_($link);

These would be the basic tricks, while other MageBridge tutorials will help you with more advanced stuff, for instance fetching all the product details of a specific product through the API.

Adding a Magento category

In the same way that you can add a Magento product to your extension, you can also add a Magento catalog-category. The type to be used here is category.

<param name="myproduct" type="category" default="" label="My Product" />

Just like the product-type, the category-type also has a return-option. By default the parameter returns the category URL, but you can also set the return-value to url_key (to get the Magento URL-key) or id (to get the Magento category ID).

More information

More information on how to use XML-parameters in your own Joomla! extension, can be find with the Joomla! Documentation project (http://docs.joomla.org/Component_parameters).

Created on Saturday, 06 March 2010
Modified on Saturday, 06 March 2010

About Yireo

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

More about Yireo