1

I have been looking into some tutorials but none of them works, for example, first they told me to open xxx files and edit something but what I found on my files is just a class with no single method inside it.

Currently I have got register.phtml(/template/persistent/customer/form) to show the custom field named Website but I don't know how to get it working with all functions of the site.

My Magento version is 1.7.0.2

Please advice.

5

To use an attribute in the frontend you have to do two things.

  1. add the attribute to the EAV
  2. tell magento that the attribute should be used and is allowed to be saved by the customer. There are lots of attributes you don't want to be saved by the customer, for example created_at, updated_at or any account balance should not be editable by the customer.

    All the attributes are saved in the different forms via

    $customerForm = Mage::getModel('customer/form');
        $customerForm->setFormCode('customer_account_create')
            ->setEntity($customer);
    

    Have a look on the form codes. They are important to change the attributes. there are a few, like customer_account_edit, customer_account_create. Just check the code if the forms doesn't save your attribute, what is needed and how the form is named.

Add the attribute

<?php
/* @var $installer Mage_Catalog_Model_Resource_Setup */
$installer = $this;

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

$installer->startSetup();

$attributes = array(
    'website' => 'Website',
);

foreach ($attributes as $name => $attribute) {
    $installer->addAttribute(
        'customer',
        $name,
        array(
             'label'        => $attribute,
             'input'        => 'text',
             'type'         => 'varchar',
             'required'     => 0,
             'user_defined' => 1,
        )
    );

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

Make attribute usable in forms

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

$installer->endSetup();

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.