1

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();
  • Did you confirm your table was created? Did you re-index? – brentwpeterson Mar 15 '15 at 17:12
  • @brentwpeterson, Im not sure which db table to look for, what name would it have? – Holly Mar 15 '15 at 17:14
  • 1
    @brentwpeterson, I found the attribute in the eav_attribute table. I realized that I could not re-index properly from the admin panel as it is a Magento EE install but could with php indexer.php --reindexall from the command line. Why is re-indexing done differently in EE I wonder? – Holly Mar 15 '15 at 22:56
  • @Holy can you add this as an answer, your solution worked for me but it would be more obvious as an excepted answer. You can accept your own answer and in this case I think that would be useful – Luke Oct 8 '15 at 20:32
  • @Luke, thanks for the feedback. I put the solution in an answer as you suggested. – Holly Oct 9 '15 at 8:33
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.

enter image description here

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.