Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer
    
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 at 18:39

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).

share|improve this answer
    
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 at 18:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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