1

I'm searching for a solution with the magento buildin way to create html select blocks. Using magento CE 1.9.0.1

My code is:

$this->setChild('designs',
        $this->getLayout()->createBlock('adminhtml/html_select')
            ->setData(array(
                'id' => 'product_option_{{id}}_design',
                'class' => 'required-entry select-type-design'
            ))
    );

    $this->getChild('designs')->setName('product[options][{{id}}][design]')
        ->setName('product[options][{{id}}][design]')
        ->setOptions($options);

$options is a array of the possible selectoptions.

How can I make one option to be selected?

I can see the functionality in the code /var/www/geschenkidee/web/app/code/core/Mage/Core/Block/Html/Select.php in the proteced method _optionToHtml. But I dont see a way to set this infomation.

1

Try adding a value element in the array you set as data.

$this->getLayout()->createBlock('adminhtml/html_select')
        ->setData(array(
            'id' => 'product_option_{{id}}_design',
            'class' => 'required-entry select-type-design',
            'value' => 'Your value to be selected here'
        ))
  • So I "only" have to find out how to get the saved attribute in my custom product option. – exe Feb 10 '15 at 15:28
  • Yes. You only need that – Marius Feb 10 '15 at 15:36
  • Seems to be done with some javascript... There is no way to get on the productdate in the customoption tab options. – exe Feb 10 '15 at 15:53
  • Ok it's working. Instead of adding the selected value in the block it has to be done in a ugly JS like all the other customoptions are be done: /app/design/adminhtml/default/default/template/catalog/product/edit/options/option.phtml – exe Feb 10 '15 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.