4

I'm trying to set the default value as "Yes" for the Is Active field on New Category. The default value is no, and the store owner gets annoyed when the category doesn't show on the frontend. I've tried using function $attribute->getDataSetDefault('default_value',1); on app\code\core\Mage\Adminhtml\Block\Catalog\Category\Tabs.php, but it didn't work.

The div content on design/adminhtml/default/default/catalog/category/edit/form.phtml is generated dinamically on Tabs.php, on this call:

$block = $this->getLayout()->createBlock($this->getAttributeTabBlock(), '')
            ->setGroup($group)
            ->setAttributes($attributes)
            ->setAddHiddenFields($active)
            ->toHtml();

I tried to debug, but after a while I had an overflow on debug memory, and it crashed. I'm still trying this.

I also tried to look at configuration files to find where the attribute is created to see if a default value is set, but I haven't find it yet.

New Category Form

12

I would advise never editing core code as it will create issues for you down the road.

This is a database change. 0 comes before 1 and no default value is set for that attribute so 0 will always be selected unless otherwise told.

You need to go into your database, find the "is_active" attribute code (there may be two, only edit the one with the Source Model of "eav/entity_attribute_source_boolean"). In "default_value" add the value of "1".

If you know how to use Queries on phpMyAdmin, that would look like:

UPDATE `eav_attribute` SET `default_value` = '1' WHERE `eav_attribute`.`attribute_code`='is_active' AND `eav_attribute`.`source_model`='eav/entity_attribute_source_boolean';

Database Change

Make sure to save you changes then try to create a new category. You should see something like this: Is Active

Note: Whenever editing a field in the database, you should always make a backup. Also, I did not to extensive testing on this, so you should test this change in a development instance first.

3
  • Fantastic! Worked like a charm. I'm also testing, until now it's ok, i had no side effects. I can't vote up because i'm new and have no reputation yet. Thanks, helped me a lot. Also thanks Peter Mortensen for editing and organizing the question, and cleaning my mess. – giancarloap May 29 '14 at 18:39
  • I am facing somewhat similar but opposite issue, I create a category attribute using install script with default value set to 0, now on frontend its effect (in if statement) is correct but in backend it shows "Yes" (for existing categories, when I create new category, No is selected by default) – Haris Feb 24 '17 at 18:58
  • Hi Haris, I am also getting the same issue as yours, I have created new attribute for categories with 'Yes / No' dropdown and for new categories its showing default value (yes) but for exesting categories its showing No values in dropdown. How I can I make dropdown to show "Yes" for existing categories. Please help.. – Abi Sharma Feb 25 '19 at 9:06
3

As you say, the form is dynamically created based on the category attributes. You could change the default value directly in the database with this SQL:

update eav_attribute set default_value=1 where entity_type_id = 3 and attribute_code='is_active';

3 stands for the entity type "category" as you can see in the eav_entity_type table.

Usually you should have an own module for store specific configuration and create an update script that makes this change programmatically:

$installer->updateAttribute('catalog/category', 'is_active', 'default_value', 1);

Where $installer needs to be configured to be of the type Mage_Eav_Model_Entity_Setup (or a subtype).

1
  • Great idea. I updated my install script, now new stores will be installed with new categories active by default. Again, I can't vote up because i'm new and have no reputation yet. – giancarloap May 29 '14 at 18:41

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.