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 am creating module in magento 1.9.1, to create a attribute for categories. I have created files as follows:

app\etc\modules\Ddevs_Ebayaff.xml

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

I am trying to call controller and mysql install script in one config file as follows

app\code\local\Ddevs\Ebayaff\etc\config.xml

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

</global>
     </config>

In IndexController, i have the following content

app\code\local\Ddevs\Ebayaff\controllers\IndexController.php

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

And my install script as follows:

app\code\local\Ddevs\Ebayaff\sql\add_category_attribute\mysql4-install-0.1.0.php

<?php
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'ddev_ebayaff_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();
share|improve this question

2 Answers 2

up vote 4 down vote accepted

You are missing this in the config.xml inside the <global> tag

    <resources>
        <add_category_attribute>
            <setup>
                <module>Ddevs_Ebayaff</module>
                <class>Mage_Catalog_Model_Resource_Setup</class>
            </setup>
        </add_category_attribute>
    </resources>

also change this section from the same config file

<ddevs_ebayaff>
    <version>
        0.1.0
    </version>
</ddevs_ebayaff>

to

<Ddevs_Ebayaff>
    <version>0.1.0</version>
</Ddevs_Ebayaff>
share|improve this answer
    
Hi, thanks for your reply. I changed the xml file according to your suggestion, but still no luck in creating category attribute. –  dynamic devs 20 hours ago
    
The code looks right in rest. Maybe the problem is different. Try to debug using this: magento.stackexchange.com/q/428/146. and this to see how it's done: atwix.com/magento/add-category-attribute –  Marius 19 hours ago
    
I tried to debug, but no errors are showing up and the module is not going through the mysql4-install-0.1.0.php. Even if i add die statement into it, nothing is happening. –  dynamic devs 18 hours ago
    
maybe your module was already installed. check the table core_resource for a line with code add_category_attribute. If there is one, delete it. –  Marius 18 hours ago
    
Thanks for your help!!, I uninstalled the extension completely and installed again and the attribute is created correctly. Thanks once again.. –  dynamic devs 15 hours ago

For your specific problem, you are missing the <resources> configuration in your module config. You need to add it directly under the <global> tag

<resources>
    <add_category_attribute>
        <setup>
            <module>Ddevs_Ebayaff</module>
            <class>Mage_Eav_Model_Entity_Setup</class>
        </setup>
    </add_category_attribute>
</resources>

The <add_category_attribute> tag should be the same as the directory name which contains your install scripts.

Other than that, you have different issues in your config.xml.

You cannot put a <frontend> tag inside <global>. The thing is, most of your module configuration fall under ONE of three tags.

  • <frontend>
    Configuration under this tag, applies only to the frontend of Magento.
    These can be for example new routes just for the frontend.
  • <admin>
    Configuration under this tag, applies only to the backend of Magento.
    These can be for example new routes just for the backend
  • <global>
    Configuration under this tag, applies everywhere in Magento.
    These can be for example configuration for models, block, helpers.

This is how your config.xml should be:

<?xml version="1.0"?>
<config>
    <modules>
        <Ddevs_Ebayaff>
            <version>0.1.0</version>
        </Ddevs_Ebayaff>
    </modules>
    <global>
        <resources>
            <add_category_attribute>
                <setup>
                    <module>Ddevs_Ebayaff</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
            </add_category_attribute>
        </resources>
    </global>
    <frontend>
        <routers>
            <helloworld>
                <use>standard</use>
                <args>
                    <module>Ddevs_Ebayaff</module>
                    <frontName>ebayaffload</frontName>
                </args>
            </helloworld>
        </routers>
    </frontend>
</config>
share|improve this answer
    
Hi, I replaced the config file with the above, but category attribute is not creating yet. –  dynamic devs 19 hours ago
    
@dynamicdevs Do you get an error when you open Magento or does it open normally? Can you post the output of the following MySQL query select version, data_version from core_resource where code='add_category_attribute';? –  Dan 19 hours ago
    
Thanks for your help!!, I uninstalled the extension completely and installed again and the attribute is created correctly. Thanks once again.. –  dynamic devs 15 hours ago

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.