I don’t know what you tried, so I’ll just list all the steps necessary to add a new schooL client attribute to the Magento 1.6.1 registration form.
Create a module preferably or put some code into it in the .phtml file and run it once. If you do this correctly and create the module, add this code to the mysql_install file:
<?php $installer = $this; $installer->startSetup(); $setup = Mage::getModel('customer/entity_setup', 'core_setup'); $setup->addAttribute('customer', 'school', array( 'type' => 'int', 'input' => 'select', 'label' => 'School', 'global' => 1, 'visible' => 1, 'required' => 0, 'user_defined' => 1, 'default' => '0', 'visible_on_front' => 1, 'source'=> 'profile/entity_school', )); if (version_compare(Mage::getVersion(), '1.6.0', '<=')) { $customer = Mage::getModel('customer/customer'); $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId(); $setup->addAttributeToSet('customer', $attrSetId, 'General', 'school'); } if (version_compare(Mage::getVersion(), '1.4.2', '>=')) { Mage::getSingleton('eav/config') ->getAttribute('customer', 'school') ->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register')) ->save(); } $installer->endSetup(); ?>
In your module config.xml file. Please note that my module name is Excellence_Profile.
<profile_setup> <setup> <module>Excellence_Profile</module> <class>Mage_Customer_Model_Entity_Setup</class> </setup> </profile_setup>
Here we will add our attribute to the customer registration form. In version 1.6.0 (+), the used phtml persistance/customer/register.phtml
file is used, and in 1.6.0 (-) the used phtml customer/form/register.phtml
file is used. Therefore, we need to open the phtml file based on the magento version and add this code to the tag.
<li> <?php $attribute = Mage::getModel('eav/config')->getAttribute('customer','school'); ?> <label for="school" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label> <div class="input-box"> <select name="school" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>"> <?php $options = $attribute->getSource()->getAllOptions(); foreach($options as $option){ ?> <option value='<?php echo $option['value']?>' <?php if($this->getFormData()->getSchool() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option> <?php } ?> </select> </div> </li>
For magento 1.4.2 (+), this is all that is required for the registration phase. If you create a user here, you should see the school text field in admin. For magento 1.4.1 (-), we need to do one more thing to open your modules.xml file of your module and add:
<global> <fieldsets> <customer_account> <school><create>1</create><update>1</update><name>1</name></school> </customer_account> </fieldsets> </global>
Once the user has created his account in the "My Account Information" section, he will also be able to edit the school field. To do this, open the phtml customer/form/edit.phtml
and enter the code in:
<?php <li> <?php $attribute = Mage::getModel('eav/config')->getAttribute('customer','school'); ?> <label for="is_active" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label> <div class="input-box"> <select name="school" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>"> <?php $options = $attribute->getSource()->getAllOptions(); foreach($options as $option){ ?> <option value='<?php echo $option['value']?>' <?php if($this->getCustomer()->getSchool() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option> <?php } ?> </select> </div> </li>
The registration form is also displayed on the verification page in purple. To add a field here, you need to edit checkout/onepage/billing.phtml
for magento version 1.6 (-) and persistant/checkout/onepage/billing.phtml
for magento version 1.6 (+), and then find the code:
<?php if(!$this->isCustomerLoggedIn()): ?>
inside this condition if add your field
<li> <li> <?php $attribute = Mage::getModel('eav/config')->getAttribute('customer','school'); ?> <label for="school" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label> <div class="input-box"> <select name="billing[school]" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>"> <?php $options = $attribute->getSource()->getAllOptions(); foreach($options as $option){ ?> <option value='<?php echo $option['value']?>'><?php echo $this->__($option['label'])?></option> <?php } ?> </select> </div> </li>
Then open the config.xml file or any other config.xml file, add the following lines:
<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>
Next, we need to make some changes to the ie quotation table in the sales_flat_quote table in magento. If you have a module, create an updated version of your SQL file and put this code:
$tablequote = $this->getTable('sales/quote'); $installer->run(" ALTER TABLE $tablequote ADD `customer_school` INT NOT NULL ");
After that, be sure to clear the magento cache, in particular Flush Magento Cache and Flush Cache Storage. Now, when you place an order, the customer is created with the correct school attribute.