0
votes

I'm trying to add an attribute through a setup script in a module but it's not showing in the admin panel.

Here's what I have:

app/etc/modules/MyCompanyName_UpgradeScripts.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MyCompanyName_UpgradeScripts>
            <active>true</active>
            <codePool>local</codePool>
        </MyCompanyName_UpgradeScripts>
    </modules>
</config>

app/code/local/MyCompanyName/UpgradeScripts/controllers/IndexController.php

<?php
class MyCompanyName_UpgradeScripts_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
        $this->loadLayout();
        $this->renderLayout();
    }
}

app/code/local/MyCompanyName/UpgradeScripts/etc/config.xml

<?xml version="1.0"?> <config>
    <modules>
        <mycompanyname_upgradescripts>
            <version>
                0.1.0
            </version>
        </mycompanyname_upgradescripts>
    </modules>
    <global>
        <resources>
            <add_category_attribute>
                <setup>
                    <module>MyCompanyName_UpgradeScripts</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
            </add_category_attribute>
        </resources>
    </global>
    <frontend>
        <routers>
            <helloworld>
                <use>standard</use>
                <args>
                    <module>MyCompanyName_UpgradeScripts</module>
                    <frontName>ebayaffload</frontName>
                </args>
            </helloworld>
        </routers>
    </frontend>
</config>

app/code/local/MyCompanyName/UpgradeScripts/add_category_attribute\mysql4-install-0.1.0.php

<?php
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'mycompanyname_upgradescripts_cat', array(
    'group'         => 'General Information',
    'input'         => 'text',
    'type'          => 'text',
    'label'         => 'Category ID',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$this->endSetup();
1

1 Answers

0
votes

Add ctegory attribute.

File structure :

app/code/local/Amanweb/Catattr/etc/config.xml app/code/local/Amanweb/Catattr/Helper/Data.php app/code/local/Amanweb/Catattr/sql/categoryaddattr_setup/mysql4-install-0.1.0.php app/etc/modules/Amanweb_Catattr.xml

Code in config.xml

    <?xml version="1.0"?>
    <config>
      <modules>
        <Amanweb_Catattr>
          <version>0.1.0</version>
        </Amanweb_Catattr>
      </modules>
      <global>
        <helpers>
          <catattr>
            <class>Amanweb_Catattr_Helper</class>
          </catattr>
        </helpers>
        <models>
          <catattr>
            <class>Amanweb_Catattr_Model</class>
            <resourceModel>catattr_mysql4</resourceModel>
          </catattr>
        </models>
        <resources>
          <categoryaddattr_setup>
            <setup>
              <module>Amanweb_Catattr</module>
              <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
            </setup>
            <connection>
              <use>core_setup</use>
            </connection>
          </categoryaddattr_setup>
          <categoryaddattr_write>
            <connection>
              <use>core_write</use>
            </connection>
          </categoryaddattr_write>
          <categoryaddattr_read>
            <connection>
              <use>core_read</use>
            </connection>
          </categoryaddattr_read>
        </resources>
      </global>
    </config>

Code in Data.php class Amanweb_Catattr_Helper_Data extends Mage_Core_Helper_Abstract { }

Code in mysql4-install-0.1.0.php

    $installer = $this;
    $installer->startSetup();
    $installer->removeAttribute('catalog_category','bottomblock_image');
    $installer->addAttribute("catalog_category", "bottomblock_image",  array(
        "type"     => "text",
        "backend"  => "",
        "frontend" => "",
        "label"    => "Label",
        "input"    => "text",
        "class"    => "",
        "source"   => "",
        "global"   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        "visible"  => true,
        "required" => false,
        "user_defined"  => false,
        "default" => "",
        "searchable" => false,
        "filterable" => false,
        "comparable" => false,
        "visible_on_front"  => true,
        "unique"     => false,
        "note"       => "",
        'group' => "Custom Design"
    ));
    $installer->endSetup();

Code in Amanweb_Catattr.xml

    <?xml version="1.0"?>
    <config>
      <modules>
        <Amanweb_Catattr>
          <active>true</active>
          <codePool>local</codePool>
          <version>0.1.0</version>
        </Amanweb_Catattr>
      </modules>
    </config>

Note : if your setup script is not working then check your core_resource table their is entry for your module setup delete that entry and refresh magento cache from admin and it should work properly.