Reputation: 4292
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
Upvotes: 1
Views: 1751
Reputation: 5712
Just skimming over it, I noticed that your config/xml file has the following:
<ncategoryattributes_setup_write>
Try removing the 'n'.
Upvotes: 1