Tag Archives: store

How to show the default checkbox near a Magento attribute

It is annoying that Magento doesn’t have a much easier way to insert this thing. What am I talking about? See this screenshot:

Default checkbox in product pages

Well, this is quite an ugly solution, but maybe it will work for you. First of all, on product pages there is a custom renderer for each element, that is why it is shown there. So, if you have the following element:

$name = $fieldset->addField('name', 'text', array(
    'name' => 'name',
    'required' => true,
    'class' => 'required-entry',
    'label' => Mage::helper('some_helper')->__('Name'),
));

you will have to render it with a custom renderer:

if ($name)
{
    $name->setRenderer(
        $this->getLayout()->createBlock('adminhtml/catalog_form_renderer_fieldset_element')
    );
}

At this point you should have the third column with the scope-label class. But the checkbox near it still won’t show up. For that we have to set the following for the form:

$storeObj = new Varien_Object();
$storeId = $this->getRequest()->getParam("store");
$storeObj->setId($storeId);
$storeObj->setStoreId($storeId);
$form->setDataObject($storeObj);

Now you should see also the checkbox. That’s all folks!