Release of newer version of jQuery Lightboxes 1.2.0

February 28, 2012  |  3 Comments  |  by Raj (MagePsycho)  |  jQuery, Latest, Magento


Magento community is showing great love towards the Magento Extension: jQuery Lightboxes (probably the #1 lightbox extension for Magento e-Commerce), as a result we are on the way to make it much better with lots of new features.
Just we have released a newer version of jQuery Lightboxes i.e. 1.2.0.


Version 1.1.0 – 1.2.0
– Tested Compatibility with Magento Version
– Upgraded jQuery Version (local + Google CDN) to 1.7.1
– Added Option to include Main Image to lightbox gallery of More Views
– Added Option to change the label for ‘More Views’
– Upgraded FancyBox to version 1.3.4
– Changed the default settings of FancyBox so that it looks even more sexier
– Added new Lightbox Type: PiroBox Extended (advanced form of Pirobox)
– Added new Lightbox Type: prettyPhoto
– Code Refinement

You can download the latest version of it either from
1> Official Site
2> Magento-Connect

Try once and let me know your feedback/suggestions if there’s any.
Thanks a lot for loving this extension!

Demystifying PHP’s Array Key/Index

February 14, 2012  |  No Comments  |  by Raj (MagePsycho)  |  Latest, Magento, PHP

According to manual:

An array in PHP is actually an ordered map. A map is a type that associates values to keys.

A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. “8” will be interpreted as 8, while “08” will be interpreted as “08”). Floats in key are truncated to integer. The indexed and associative array types are the same type in PHP, which can both contain integer and string indices.

Well that’s just a bit of defination about Array and it’s key/index.
Let’s play with some practical examples.
Suppose say you are making a dropdown field for Opacities(0, 0.1, 0.2, … 0.9, 1) for your System > Configuration field (Magento) and using your source model as:

class MagePsycho_Custommodule_Model_System_Config_Source_Opacity
    public function toOptionArray()
        $range = range(0, 1, 0.1);
        $array = array();
        foreach($range as $val){
            $array[$val] = $val;
        return $array;

When you try to load the page in System > Configuration for your module you will see that only there is only one value in dropdown i.e.

<option value="0">1</option>

You must be wondering where are the other values (0 – 0.9)?
Now the role of key/index comes into play.

As per above defination: An array key/index can only be an integer or a string type. But here index is a float type and php will convert it to an integer type and any float value: 0.1 – 0.9 will be converted to integer: 0.

But if you modify the above code as:

class MagePsycho_Custommodule_Model_System_Config_Source_Opacity
    public function toOptionArray()
        $range = range(0, 1, 0.1);
        $array = array();
        foreach($range as $val){
            $array["$val"] = $val; //note the double quotes around the key
        return $array;

You must have noted the double quotes around the key and using the double quotes will populate all the values from 0 – 1.
This is because PHP tries to interpolate the variable inside the double quotes and return as string. And the key looks like: For example:


which is a string key not a float one.

Hope this helps you to get some understanding of proper usage of indexing in an Array.
Thanks for Reading!

How to use WYSIWYG editor (TinyMCE) in custom Admin Magento Module

February 7, 2012  |  13 Comments  |  by Raj (MagePsycho)  |  Javascript, Latest, Magento

Rich text editor(TinyMCE) is an often requirement for Admin Module as it makes the content editing work much more easier.
In order to enable TinyMCE editor in textarea field, You need to do the following two things:

1> Including TincyMCE in Head

Add the following function in your Adminhtml Edit Class (MagePsycho_Demomodule_Block_Adminhtml_Demomodule_Edit):

protected function _prepareLayout() {
	if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {

2> Enabling in Form Field

Add the following content field in your Adminhtml Form class (MagePsycho_Demomodule_Block_Adminhtml_Demomodule_Edit_Tab_Form):

$fieldset->addField('content', 'editor', array(
	'name'      => 'content',
	'label'     => Mage::helper('demomodule')->__('Content'),
	'title'     => Mage::helper('demomodule')->__('Content'),
	'style'     => 'height:15em',
	'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
	'wysiwyg'   => true,
	'required'  => false,

Note: Field Type must be ‘editor’ and ‘wysiwyg’ must be true

3> That’s All.

Here is what it looks like when loaded:

TinyMCE Editor

Note that this code was tested in Magento Version
Happy Editing!