3

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();
Ashhar Azeez
  • 147
  • 1
  • 3
  • 14

2 Answers2

4

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>
Marius
  • 197,939
  • 53
  • 422
  • 830
  • Hi, thanks for your reply. I changed the xml file according to your suggestion, but still no luck in creating category attribute. – Ashhar Azeez Jun 11 '15 at 14:04
  • The code looks right in rest. Maybe the problem is different. Try to debug using this: http://magento.stackexchange.com/q/428/146. and this to see how it's done: http://www.atwix.com/magento/add-category-attribute/ – Marius Jun 11 '15 at 14:07
  • 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. – Ashhar Azeez Jun 11 '15 at 15:22
  • 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 Jun 11 '15 at 15:28
  • Thanks for your help!!, I uninstalled the extension completely and installed again and the attribute is created correctly. Thanks once again.. – Ashhar Azeez Jun 11 '15 at 18:43
3

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>
Dan
  • 1,223
  • 8
  • 25
  • Hi, I replaced the config file with the above, but category attribute is not creating yet. – Ashhar Azeez Jun 11 '15 at 14:08
  • @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 Jun 11 '15 at 15:06
  • Thanks for your help!!, I uninstalled the extension completely and installed again and the attribute is created correctly. Thanks once again.. – Ashhar Azeez Jun 11 '15 at 18:43