0

I want to add few custom attribute to General Information in Magento > Catalog > Manage Category

But this not going to work. Please help me to find out here are my code below.

modules/Wri_CustomCategoryAttribute.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Wri_CustomCategoryAttribute>
            <active>true</active>
            <codePool>community</codePool>
        </Wri_CustomCategoryAttribute>
    </modules>
</config>

community/Wri/CustomCategoryAttribute/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Wri_CustomCategoryAttribute>
            <version>0.0.1</version>
        </Wri_CustomCategoryAttribute>
    </modules>

    <global>
        <resources>
            <add_category_attribute>
                <setup>
                    <module>Wri_CustomCategoryAttribute</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </add_category_attribute>
            <add_category_attribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </add_category_attribute_write>
            <add_category_attribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </add_category_attribute_read>
        </resources>
    </global>
</config>

community/Wri/CustomCategoryAttribute/sql/add_category_attribute/mysql4-install-0.0.1.php

<?php
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'h2_text', array(
    'group'         => 'General Information',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'H2 Text',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'view_more_text', array(
    'group'         => 'General Information',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'View More Text',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));


$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'view_more_link', array(
    'group'         => 'General Information',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'View More Links',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

$this->endSetup();

I am following instructions from here

1

Try it like this:

 $installer = Mage::getResourceModel('catalog/eav_mysql4_setup', 'core_setup');

    $installer->startSetup();

   $installer->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'h2_text', array(
    'group'         => 'General Information',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'H2 Text',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

$installer->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'view_more_text', array(
    'group'         => 'General Information',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'View More Text',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));


$installer->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'view_more_link', array(
    'group'         => 'General Information',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'View More Links',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));

Then add those attributes to attribute_set:

$setId = Mage::getSingleton('eav/config')->getEntityType('catalog_category')->getDefaultAttributeSetId();

$attributesCodes = ['h2_text', 'view_more_text', 'view_more_link'];


foreach ($attributesCodes as $attrCode) {
        $installer->addAttributeToGroup('catalog_category', $setId, 'General Information', $attrCode);
    }
}

$installer->endSetup();
7
  • Where I have to this section "Then add those attributes to attribute_set:" – Vikas Kumar Tiwari Mar 17 '18 at 9:41
  • In the same installer file :) – dudzio Mar 17 '18 at 9:42
  • You can also try to change your: <class>Mage_Catalog_Model_Resource_Setup</class> To: <class>Mage_Eav_Model_Entity_Setup</class> So you don't have to use $installer = Mage::getResourceModel('catalog/eav_mysql4_setup', 'core_setup'); and you can use just $this – dudzio Mar 17 '18 at 9:42
  • There is a chance that your installer worked, but it didn't create attribute_set link, so you have to check in eav_attribute table if attributes appeared, look for your codes in attribute_code column. Write down id's for those rows. Add new records to eav_entity_attribute table with your new attribute_id's and default (or your custom) attribute_set_id and correct entity_type_id. – dudzio Mar 17 '18 at 9:47
  • Thanks @dudzio but still not working – Vikas Kumar Tiwari Mar 17 '18 at 9:54
1
    <?php
    $installer = $this;
    $installer->startSetup();

    $attribute  = array(
            'group'                     => 'General',
            'input'                     => 'textarea',
            'type'                      => 'text',
            'label'                     => 'H2 Text',
            'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'visible'                   => 1,
            'required'                  => 0,
            'visible_on_front'          => 0,
            'is_html_allowed_on_front'  => 0,
            'is_configurable'           => 0,
            'searchable'                => 0,
            'filterable'                => 0,
            'comparable'                => 0,
            'unique'                    => false,
            'user_defined'              => false,
            'is_user_defined'           => false,
            'used_in_product_listing'   => true
    );

    $installer->addAttribute('catalog_category', 'h2_text', $attribute);
$attribute  = array(
        'group'                     => 'General',
        'input'                     => 'textarea',
        'type'                      => 'text',
        'label'                     => 'View More Text',
        'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'                   => 1,
        'required'                  => 0,
        'visible_on_front'          => 0,
        'is_html_allowed_on_front'  => 0,
        'is_configurable'           => 0,
        'searchable'                => 0,
        'filterable'                => 0,
        'comparable'                => 0,
        'unique'                    => false,
        'user_defined'              => false,
        'is_user_defined'           => false,
        'used_in_product_listing'   => true
);

$installer->addAttribute('catalog_category', 'view_more_trext',      $attribute);
   $attribute  = array(
        'group'                     => 'General',
        'input'                     => 'textarea',
        'type'                      => 'text',
        'label'                     => 'View More Links',
        'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'                   => 1,
        'required'                  => 0,
        'visible_on_front'          => 0,
        'is_html_allowed_on_front'  => 0,
        'is_configurable'           => 0,
        'searchable'                => 0,
        'filterable'                => 0,
        'comparable'                => 0,
        'unique'                    => false,
        'user_defined'              => false,
        'is_user_defined'           => false,
        'used_in_product_listing'   => true
);

$installer->addAttribute('catalog_category', 'view_more_links', $attribute);
    $installer->endSetup();?>

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.