3

I add attributes in setup script, all is configured properly and attributes are added to a new tab called "MyGroup":

$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_category', 'my_attribute1', array(
    'group'         => 'MyGroup',
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'My Attribute 1',        
    'backend'       => '',
    'visible'       => 1,   
    'required'      => 0,
    'user_defined' => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,     
));
//...here add more attributes
$installer->endSetup();

This automatically creates a tab "MyGroup" and a form with fields for all the attributes which I defined in setup script.

Is there a way to have more control over the entire form inside "MyGroup" tab? For example, normally when I create an admin form I can also add dependency for fields (e.g. to hide field2 if no option selected in field1 etc.). I know how to add field dependency in custom admin form (e.g. http://www.atwix.com/magento/fields-dependency-in-magento-admin-forms/) but I don't know how to do this with category attributes.

So is there a way to override that form somehow? Or at least to add field dependency?

1
  • did you ever find a solution here? Commented Dec 11, 2014 at 10:00

2 Answers 2

1

Bad news: You cannot define dependencies in attributes, so yes, you will need to manipulate the form directly like in the linked article(s).

Good news: No rewrites are required, there is an observer that you can use: adminhtml_catalog_category_edit_prepare_form

It's triggered for each group in Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes::_prepareForm() and has the Varien_Data_Form as parameter, that you can access with:

$form = $observer->getForm()

At this point all attributes are already added to a fieldset called fieldset_group_{$groupId} - by checking for the fieldset you can identify the currently rendered tab. You need to know the group ID of your tab. Unfortunately the group object itself is not passed to the observer.

0

I have created simple category attribute dependency by adding new input renderer for attribute. It is working this way: You have several attributes:

– my_attribute
– my_attribute_text
– my_attribute_select

Note that they all start from my_attribute.

First attribute has boolean type. When it is set to true – other attributes that start from my_attribute is visible.

Source - https://github.com/elpas0/category_dependence

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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