1

This afternoon I've been trying to create a module in Magento that simply adds some more attributes to categories.

I'll run through the script I've created so far...

app/etc/Modules/Comp_Categoryattributes.xml

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

app/code/local/Comp/Categoryattributes/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Comp_Categoryattributes>
            <version>0.1.0</version>
        </Comp_Categoryattributes>
    </modules>
    <global>
        <models>
            <categoryattributes>
                <class>Comp_Categoryattributes_Model</class>
                <resourceModel>categoryattributes_mysql4</resourceModel>
            </categoryattributes>
            <categoryattributes_mysql4>
                <class>Comp_Categoryattributes_Model_mysql4</class>
            </categoryattributes_mysql4>
        </models>
        <resources>
            <categoryattributes_setup>
                <setup>
                    <module>Comp_Categoryattributes</module>
                    <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </categoryattributes_setup>
            <ncategoryattributes_setup_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </categoryattributes_setup_write>
            <categoryattributes_setup_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </categoryattributes_setup_read>
        </resources>
    </global>
</config>

And then finally, this one courtesy of http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/ app/code/local/Comp/Categoryattributes/sql/categoryattributes_setup/mysql4-install-0.1.0.php

<?php

$installer = $this;
$installer->startSetup();

$entityTypeId     = $installer->getEntityTypeId('catalog_category');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$installer->addAttribute('catalog_category', 'twitter_user',  array(
    'type'     => 'int',
    'label'    => 'Twitter Username',
    'input'    => 'text',
    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => false,
    'default'           => 0
));

$installer->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'twitter_user',
    '11'                    //last Magento's attribute position in General tab is 10
);

$attributeId = $installer->getAttributeId($entityTypeId, 'twitter_user');

$installer->run("
INSERT INTO `{$installer->getTable('catalog_category_entity_int')}`
(`entity_type_id`, `attribute_id`, `entity_id`, `value`)
    SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
        FROM `{$installer->getTable('catalog_category_entity')}`;
");

//this will set data of your custom attribute for root category
Mage::getModel('catalog/category')
    ->load(1)
    ->setImportedCatId(0)
    ->setInitialSetupFlag(true)
    ->save();

//this will set data of your custom attribute for default category
Mage::getModel('catalog/category')
    ->load(2)
    ->setImportedCatId(0)
    ->setInitialSetupFlag(true)
    ->save();

$installer->endSetup();

?>

The module appears in the Disable Module Output area of the back end fine, but I don't see categoryattribute_setup appearing in the core_resource table at all? Is there something obvious I'm missing?

Cheers guys,

Tom

3
  • Throw a die() at the top of your install script, flush cache, and hit any page of your site (just need Mage::run() to fire). See if you die. Commented Nov 2, 2011 at 21:45
  • 1
    ... and don't forget to remove the entry in the core_setup table for your module, otherwise no new installation will executed Commented Nov 3, 2011 at 6:51
  • Cheers for the replies chaps. Ben - I've added a die() into my install script but the sites works as normal. I guess this pretty much confirms my thoughts that its not actually being loaded in. Danny - I don't see a core_setup table? It doesn't appear in core_resources though, where the rest of the _setup entries are for the other modules. Commented Nov 3, 2011 at 8:57

1 Answer 1

1

Just skimming over it, I noticed that your config/xml file has the following:

<ncategoryattributes_setup_write>

Try removing the 'n'.

Sign up to request clarification or add additional context in comments.

1 Comment

Yup, spotted, its always the little things that trip you over isn't it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.