I've tried adding a new attribute to the Magento Categories which I can configure from the Admin Panel Category -> Manage Categories. The attribute is called custom_attribute.
I created a module similar to these tutorials which I followed, Atwix & ashsmith.
After completing the tutorials I can see my custom attribute on the back end from the admin panel.
But I get the below error when I try to save the category.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'custom_attribute' in 'field list'
Also I can't access the attribute from a template file with <?php $_category->getCustomAttribute() ?>, it just returns null in the debugger.
Here is my modules config.xml
<?xml version="1.0"?>
<config>
<modules>
<Creed_CustomAttribute>
<version>0.1.0</version>
</Creed_CustomAttribute>
</modules>
<global>
<blocks>
<page>
<rewrite>
<html_topmenu>Creed_CustomAttribute_Block_Page_Html_Topmenu</html_topmenu>
</rewrite>
</page>
</blocks>
<resources>
<customattribute_setup>
<setup>
<module>Creed_CustomAttribute</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
<connection>
<use>default_setup</use>
</connection>
</customattribute_setup>
<customattribute_setup_write>
<connection>
<use>core_write</use>
</connection>
</customattribute_setup_write>
<customattribute_setup_read>
<connection>
<use>core_read</use>
</connection>
</customattribute_setup_read>
</resources>
</global>
</config>
And here is my mysql4-install-0.1.0.php
<?php
/**
*/
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_category', 'custom_attribute', array(
'group' => 'General Information',
'type' => 'int',//can be int, varchar, decimal, text, datetime
'backend' => '',
'frontend_input' => '',
'frontend' => '',
'label' => 'Custom Attribute Label',
'input' => 'select', //text, textarea, select, file, image, multilselect
'default' => 0, // Set to False
'class' => '',
'source' => 'eav/entity_attribute_source_boolean',//this is necessary for select and multilelect, for the rest leave it blank
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
'visible' => true,
'frontend_class' => '',
'required' => false,//or true
'user_defined' => true,
'position' => 110,//any number will do
));
$installer->endSetup();
1 Answer 1
I was able to solve this issue by re-indexing. However with Magento EE you cannot re-index all the indexers manually from the admin panel, EE performs partial indexing for the most of the indexers by cron job, which is faster and better for performance, see Magento docs for more details.
So to manually re-index all of the indexers I had to re-index from the terminal, this is done with the php indexer.php --reindexall command from within the Magento shell directory.
$ cd shell/
$ php indexer.php --reindexall
Category Flat Data index was rebuilt successfully
Product Flat Data index was rebuilt successfully
Stock Status index was rebuilt successfully
Catalog product price index was rebuilt successfully
Category URL Rewrites index was rebuilt successfully
Product URL Rewrites index was rebuilt successfully
URL Redirects index was rebuilt successfully
Catalog Category/Product Index index was rebuilt successfully
Catalog Search Index index was rebuilt successfully
Tag Aggregation Data index was rebuilt successfully
Attribute Splash index was rebuilt successfully
Amasty Color Swatches Pro index was rebuilt successfully
Product Attributes index was rebuilt successfully
$
For more information on how to re-index from the terminal see this useful blog post from Inchoo.
Explore related questions
See similar questions with these tags.
php indexer.php --reindexallfrom the command line. Why is re-indexing done differently in EE I wonder?