0

I created a custom attribute for customer module using below install script:

<?php
$installer = $this;

$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$installer->addAttribute("customer", "mobile",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Mobile Number",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => "Mobile Number"

        ));

        $attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "mobile");


$setup->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'mobile',
    '999'  //sort_order
);

$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
//$used_in_forms[]="adminhtml_checkout";
        $attribute->setData("used_in_forms", $used_in_forms)
                ->setData("is_used_for_customer_segment", true)
                ->setData("is_system", 0)
                ->setData("is_user_defined", 1)
                ->setData("is_visible", 1)
                ->setData("sort_order", 100)
                ;
        $attribute->save();
$installer->endSetup();

new mobile attribute created in eav_attribute table. But while retrieving in customer edit form using below, mobile attribute is missing there.

<?php
     Mage::log(print_r($this->getCustomer()->getData(), true), null, 'customer.log');
?>

Below is the output I got:

(
            [entity_id] => 23
            [entity_type_id] => 1
            [attribute_set_id] => 0
            [website_id] => 1
            [email] => [email protected]
            [group_id] => 1
            [increment_id] => 
            [store_id] => 1
            [created_at] => 2015-10-18T11:56:26+04:00
            [updated_at] => 2015-10-18 11:56:26
            [is_active] => 1
            [disable_auto_group_change] => 0
            [created_in] => Default Store View
            [firstname] => Anto
            [lastname] => Jaskaran
            [password_hash] => 7bda12fd6b2ecea227d55f088f5b653e:FBVp10XN6FZWBXZ8v0waWazWAw5KYreX
        )
3
  • 1
    You need to save a value for your new attribute in order to see it in the log. Does your attribute field appear in the admin form?
    – Marius
    Commented Oct 19, 2015 at 6:54
  • @Marius thanks for the reply. In admin only a blank text box is showing. Not the value.
    – Anto S
    Commented Oct 19, 2015 at 6:56
  • @Marius thanks for the hint. I corrected it. Now it is proper.
    – Anto S
    Commented Oct 19, 2015 at 7:18

1 Answer 1

2

Based on the comments....
An attribute appears on the customer instance if there is a value for that attribute in the database.
You need to save the customer instance from the backend first and then it will appear. in the _data array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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