Search This Blog

Friday 29 June 2012

Magento: Show Optgroup in select box

Here Furniture is OptGroup. Copy and paste in any PHTML file and check the output.

$options = array(0=>array('label' => 'Furniture',
                          'value' => array
                            (
                                0 => array
                                (
                                    'label' => 'Chair',
                                    'value' => 1
                                ),
                                1 => array
                                (
                                    'label' => 'Couch',
                                    'value' => 2
                                )
                            )
                        )
                    );
$tmp = Mage::app()->getLayout()->createBlock('core/html_select')
            ->setName('product_id')
            ->setId('product_id')
            ->setTitle('products')
            ->setClass('validate-select');
$select $tmp->setOptions($options);
echo $select->getHtml();

1 comment: