0

I've followed this tutorial exactly through step 2. I actually placed all of the files except those in the design directory that he has available for download into my app directory. Coincidentally, I am also trying to add the "school" attribute so so far I have not changed a thing. I see "school" in eav_attribute table. The module is listed as enabled in system>configuration>advanced>module output. I have reindexed and flushed cache, logged in and out. I still cannot see a "school" attribute when I try to edit a customer. I am using vs 1.7. Should this field be found in the "account information" tab for the customer? Is there anything outdated about this tutorial?

This is all in the code download, but for reference (he was missing the close of php tags, so I added those too): controllers/IndexController.php

<?php
class Excellence_Profile_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {

        $this->loadLayout();     
        $this->renderLayout();
    }
}
?>

etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Excellence_Profile>
            <version>0.1.0</version>
        </Excellence_Profile>
    </modules>
    <frontend>
        <routers>
            <profile>
                <use>standard</use>
                <args>
                    <module>Excellence_Profile</module>
                    <frontName>profile</frontName>
                </args>
            </profile>
        </routers>
        <layout>
            <updates>
                <profile>
                    <file>profile.xml</file>
                </profile>
            </updates>
        </layout>
    </frontend>
    <admin>
        <routers>
            <profile>
                <use>admin</use>
                <args>
                    <module>Excellence_Profile</module>
                    <frontName>profile</frontName>
                </args>
            </profile>
        </routers>
    </admin>
    <global>
     <fieldsets>
       <checkout_onepage_quote>
         <customer_school>
             <to_customer>school</to_customer>
         </customer_school>
       </checkout_onepage_quote>
        <customer_account>
            <school>
                <to_quote>customer_school</to_quote>
            </school>
        </customer_account>    
      </fieldsets>
    </global>
    <global>
        <fieldsets>
            <customer_account>
                 <school><create>1</create><update>1</update><name>1</name></school>
            </customer_account>
        </fieldsets>
    </global>
    <global>
        <models>
            <profile>
                <class>Excellence_Profile_Model</class>
                <resourceModel>profile_mysql4</resourceModel>
            </profile>
            <profile_mysql4>
                <class>Excellence_Profile_Model_Mysql4</class>
                <entities>
                    <profile>
                        <table>profile</table>
                    </profile>
                </entities>
            </profile_mysql4>
        </models>
        <resources>
            <profile_setup>
                <setup>
                    <module>Excellence_Profile</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </profile_setup>
            <profile_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </profile_write>
            <profile_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </profile_read>
        </resources>
        <blocks>
            <profile>
                <class>Excellence_Profile_Block</class>
            </profile>
        </blocks>
        <helpers>
            <profile>
                <class>Excellence_Profile_Helper</class>
            </profile>
        </helpers>
    </global>
</config>

Model/Entity/School

<?php
class Excellence_Profile_Model_Entity_School extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    public function getAllOptions()
    {
        if ($this->_options === null) {
            $this->_options = array();
            $this->_options[] = array(
                    'value' => '',
                    'label' => 'Choose Option..'
            );
            $this->_options[] = array(
                    'value' => 1,
                    'label' => 'School1'
            );
            $this->_options[] = array(
                    'value' => 2,
                    'label' => 'School2'
            );
            $this->_options[] = array(
                    'value' => 3,
                    'label' => 'School3'
            );

        }

        return $this->_options;
    }
}
?>
  • I doubt that you could have missed something. I used exactly the same files that you've listed above and is working perfectly fine for me. Have you ever changed any core files before trying out this module, where you could have possibly modified Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element – Shathish Jun 14 '13 at 5:44
  • That tutorial is a bit dated - it includes a bunch of stuff that hasn't been required since years, for example mapping the modul db connection to core db handles. – Vinai Jun 14 '13 at 7:08
3

Without having looked at the files he has available for download, this is the background what i needed to have a new customer attribute display in the admin account.
Check the things listed here to find the bug.

First, check the attribute is listed in the eav_attribute table, and also in the customer_eav_attribute table, which references the former by the attribute_id.
If the record in customer_eav_attribute is missing, Magento won't be able to use the attribute.

Check the customer_eav_attribute.is_visible column value is 1.

Next, check the customer_form_attribute table.

SELECT * FROM customer_form_attribute WHERE attribute_id = (SELECT attribute_id FROM eav_attribute WHERE entity_type_id=1 AND attribute_code='school');

Make sure the adminhtml_customer is part of the result set.

If all that is okay, the final thing that could be missing is that the attribute isn't assigned to the correct attribute set.
In Magento, customers always share the same attribute set. In the database it can be found using the query

SELECT attribute_set_id FROM eav_attribute_set WHERE entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code='customer');

Or, in PHP, using

Mage::getSingleton('eav/config')->getEntityType('customer')->getDefaultAttributeSetId()

To check if the attribute is associated with that attribute set, look at the eav_entity_attribute table.
This table isn't normalized like many other tables in Magento, and it's not very readable because it only contains id's.

To confirm your attribute is associated with the default attribute set, filter by your attribute_id value, and check the value of the attribute_set_id column.

If all these factors are correct, one last thing that might be causing a problem is the custom source model, if you are using a select or multiselect attribute input type.
A quick way to check if that is the problem is to change the eav_attribute.frontend_input column to text. Then the attribute input field should appear in the backend as a text input field.

If that is the case, then you know what to fix next (that is, the source model).

If all these factory are correct, your field will be visible in the backend of Magento.

  • Okay, that first sql call I change "firstname" to "school" right? And do I make the second sql call verbatim? Provided the answer to both of those questions is "yes" then I have checked all of these things and it is still not working. One strange thing I noticed is that is_system and sort_order were set to 0 for the attribute in the eav_attribute table. So I set it to 1 and 15, respectively. Reindexed, flushed cache, logged in and out, and still see nothing. I don't see errors on the server or in magento logs. – CaitlinHavener Jun 14 '13 at 16:18
  • Correct, always substitute the attribute code with what you are using. The second one is verbatim, yes. Have you turned on developer mode (via Mage::setIsDeveloperMode(true) or the MAGE_IS_DEVELOPER_MODE environment variable)? – Vinai Jun 14 '13 at 16:22
  • Logging is enabled... not sure if that is the same thing so I just inserted "#Magento Developer Mode SetEnv MAGE_IS_DEVELOPER_MODE "true"" into my .htaccess file. – CaitlinHavener Jun 14 '13 at 16:40
  • Cleared cache, tried to edit customer again, no errors in exception or system.log – CaitlinHavener Jun 14 '13 at 16:42
  • 1
    Then I don't know. All I can offer is have a look at the update scripts of this extension, they add a customer attribute with a source model. It displays fine in the admin area. Maybe install the extension and compare the values in the database. github.com/Vinai/customer-activation/tree/master/app/code/… – Vinai Jun 14 '13 at 16:49

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.