Adding Custom Signup Attributes in Magento 1.7

狂风中的少年 提交于 2019-12-03 04:01:34

you can run following script from magento root directory, this scipt add attribute to customer and accessible in create customer and edit customer detail, example i have taken 'mobile' here so you can get that attribute using getMobile() method in edit customer and create customer page.... this script also automatically add and display in admin panel try these..

define('MAGENTO', realpath(dirname(__FILE__)));

require_once MAGENTO . '/app/Mage.php';

Mage::app();



$installer = new Mage_Customer_Model_Entity_Setup('core_setup');

$installer->startSetup();

$vCustomerEntityType = $installer->getEntityTypeId('customer');
$vCustAttributeSetId = $installer->getDefaultAttributeSetId($vCustomerEntityType);
$vCustAttributeGroupId = $installer->getDefaultAttributeGroupId($vCustomerEntityType, $vCustAttributeSetId);

$installer->addAttribute('customer', 'mobile', array(
        'label' => 'Customer Mobile',
        'input' => 'text',
        'type'  => 'varchar',
        'forms' => array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'),
        'required' => 0,
        'user_defined' => 1,
));

$installer->addAttributeToGroup($vCustomerEntityType, $vCustAttributeSetId, $vCustAttributeGroupId, 'mobile', 0);

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'mobile');
$oAttribute->setData('used_in_forms', array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'));
$oAttribute->save();

$installer->endSetup();

Display attribute on Font End.

add following code to edit.phtml file located at app/design/frontend/base/default/template/customer/form/edit.phtml

<li>
     <label class="required"><?php echo $this->__('Mobile') ?><em>*</em></label>
</li>
<li>
     <input type="text" value="<?php echo $this->getCustomer()->getMobile(); ?>" title="<?php echo $this->__('Mobile') ?>" name="mobile" class="input-text validate-digits-range digits-range-1000000000-9999999999 required-entry">
</li>

As your above question i think your link will work only lower version of magento

below link would be very use full to add custom attribute to your sign up process in 1.7

use [customer-registration-fields-magento][1]

I am very happy to say that I have been able to find a solution to my problem! After posting on the Magento forum and not getting a response I decided to dive in and solve this for myself. I am hoping that my solution will help other Magento dev's that might be experiencing a similar problem.

1. I found the following tutorial which was incredibly helpful: http://www.magentocommerce.com/wiki/5_-_modules_and_development/customers_and_accounts/registration_fields

2. Unfortunately my theme did not have the register.phtml file located in: app/design/frontend/default/yourtheme/template/customer/form/

3. After reading a few other Stack Exchange and forum posts I found that in this case Magneto default's to the base located in: app/design/frontend/base with the register.phtml file located at /app/design/frontend/base/default/template/customer/form/register.phtml

4. Here's the catch that some of you also might be running into. After thinking I had figured it out, I made changes to this file and...nothing, no update on the frontend. I tried flushing the caches but it didn't work.

5. So I kept searching and found that in my case (and potentially in yours!) the register.phtml is actually stored under /app/design/frontend/base/default/template/persistent/customer/form/

6. After editing that register.phtml file I was in business

I hope this helps those of you who are running into this same issue. Feel free to update this thread if you have any questions, happy to help in any way that I can.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!