Jun 16, 2014

How to add custom new or update or delete category attribute in Magento using SQL setup

1. How to add new category attribute:

 
      
    <?php

    /** @var $this Mage_Eav_Model_Entity_Setup */

    $this->startSetup();



    /** Add new atribute */

    $this->addAttribute('catalog_category', 'ur_custom_attribute_name', array(

     'group'         => 'General Information',

     'input'         => 'textarea',

     'type'          => 'text',

     'label'         => 'ur custom attribute title',

     'backend'       => '',

     'visible'       => 1,

     'required'      => 0,

     'user_defined'     => 1,   

     'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,

    ));



    $this->endSetup();



    ?>

      

 


2. How to remove category attribute:
                   
<?php

    /** @var $this Mage_Eav_Model_Entity_Setup */

    $this->startSetup();



    /** Remove existing atribute */

    $this->removeAttribute('catalog_category', 'ur_custom_attribute_name');



    $this->endSetup();



    ?>



      

 


3. How to update category attribute:
                 
 <?php

     /** @var $this Mage_Eav_Model_Entity_Setup */

     $this->startSetup();



     /** Update existing atribute */

     $categoryEntityTypeId = $this->getEntityTypeId('catalog_category');

     $this->updateAttribute($categoryEntityTypeId, 'ur_custom_attribute_name', 'is_wysiwyg_enabled', 1);

     $this->updateAttribute($categoryEntityTypeId, 'ur_custom_attribute_name', 'is_html_allowed_on_front', 1);



     $this->endSetup();



     ?>


      

 


Note: Please add '<class>Mage_Catalog_Model_Resource_Setup</class>' in config.xml 

           
       Path: <resources>

      <affiliatetrack_setup>

       <setup>

        <module>Urnameapce_Urmodulename</module>

        <class>Mage_Catalog_Model_Resource_Setup</class>

      



 


Ignore it, if already done.
Assumption: You have created your custom module.

No comments:

Post a Comment