1

I want to get fullname of customers in magento back-end server.

enter image description here

I already brought the first name in index "NAME" and i want to join the lastname after first name.

protected function _prepareCollection()

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('name')
        ->addAttributeToSelect('firstname')
        ->addAttributeToSelect('lastname')
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('created_at')
        ->addAttributeToSelect('group_id')
        ->addAttributeToSelect('company')
        ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
        ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
        ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
        ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
        ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');

    $this->setCollection($collection);

    return parent::_prepareCollection();
}

protected function _prepareColumns()

$this->addColumn('name', array(
        'header'    => Mage::helper('customer')->__('Name'),
        'index'     => 'firstname'
    ));

How can i combine the first name and last name? Could you let me know. Thank you

1
  • **Beginner solution **- By adding 'renderer' attr, you can merge the text!
    – 3CE
    Commented Jan 27, 2017 at 17:13

1 Answer 1

3

User renderer

$this->addColumn('name', array(
        'header'    => Mage::helper('customer')->__('Name'),
        'index'     => 'firstname',
        'renderer'  => 'Namespace_Modulename_Block_Renderer_Name',
    ));

In you renderer block

<?php class Namespace_Modulename_Block_Renderer_Name extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract 
             { 

                 public function render(Varien_Object $row) { 

                     return $row->getFirstname.' '.$row->getLastname;

                 }

             }
?>
2
  • it is totallllllly work thank you!!!!!!!!
    – 3CE
    Commented Feb 7, 2017 at 19:54
  • 1
    @3CE if it is working kindly mark as accepted solution so it can help other fellow community user Commented Feb 8, 2017 at 4:36

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.