I have created custom EAV attribute for customer called branch which is select field customer need to select one branch which he/she belongs to and its working fine. Note: Customer can change the branch for each order he/she placed.

I have to store it in another table when customer place order with other customer attribute, so I used sales_order_place_after observer method. I am using

$orderInfo       = $observer->getEvent()->getOrder();

Where I can get all the information about order. I am getting all the information using this code.

$customerInfo = array(
            'customer_id'=> $orderInfo->getCustomerId(),
            'first_name' => $orderInfo->getBillingAddress()->getFirstname(),
            'last_name'  => $orderInfo->getBillingAddress()->getLastname(),
            'phone'      => $orderInfo->getBillingAddress()->getTelephone(),
            'email'      => $orderInfo->getCustomerEmail(),
            'address'    => $orderInfo->getBillingAddress()->getData('street'),
            'zip_code'   => $orderInfo->getBillingAddress()->getData('postcode'),
            'city'       => $orderInfo->getBillingAddress()->getCity(),
            'region'     => $orderInfo->getBillingAddress()->getRegion()

But I am not able to get my custom attribute, I used many ways to get it as follows.

1. Mage::log(print_r($orderInfo->getCustomerBranch(), true));
2. Mage::log(print_r($orderInfo->getBranch(), true));
3. Mage::log(print_r($orderInfo->getBillingAddress()->getData('branch'), true));
4. Mage::log(print_r($orderInfo->getBillingAddress()->getBranch(), true));

Here is the code I used to create custom attribute

install.php code

$installer = $this;
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'branch', array(
    'type' => 'varchar',
    'input' => 'select',
    'label' => 'Branch',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'default' => NULL,
    'visible_on_front' => 1,
    'source' => 'customerbranch/entity_branch',
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
      $customer = Mage::getModel('customer/customer');
      $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
      $setup->addAttributeToSet('customer', $attrSetId, 'General', 'branch');
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
    ->getAttribute('customer', 'branch')
    ->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
$tablequote = $this->getTable('sales/quote');
ALTER TABLE  $tablequote ADD  `customer_branch` varchar(255) NULL

Config.xml code



Nothing is working.:{ How can I get my attribute value in sales_order_place_after observer method?

Thanks in advance

  • How have you 'created custom EAV attribute'? Nov 17, 2014 at 15:40
  • @JonathanHussey, I will add my install.php code
    – Charlie
    Nov 17, 2014 at 15:44

1 Answer 1


You need to add a column customer_branch on the sales_flat_quote and sales_flat_order tables.
then add this in your config.xml under the fieldsets tag.


Clear the cache.
For the next orders you whould be able to get the branch like this $orderInfo->getCustomerBranch().

As a side effect, you will see the branch value in the order view page in the admin panel, below the name and e-mail address.

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.