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
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 2010Modified on Saturday, 06 March 2010
More tutorials in this section
- MageBridge plugin events
- MageBridge from the command-line
- MageBridge FAQ: Development
- Reusing MageBridge parameters in Joomla! extensions
- Catching Magento events with a Joomla! plugin
- Fetch your own Magento data from MageBridge
- Handling events with MageBridge (in progress)
- How can I create a language-pack for MageBridge?
- Creating custom store connectors
- Discovering the MageBridge Magento package
