Magento – Set Default Value of ‘Is Active’ to ‘Yes’ for New Category

adminformcatalogcategory-attributece-1.7.0.2

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

Best Answer

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.