Magento 1.9.x - I want to join first name and last name in customer grid
-
06-10-2020 - |
質問
I want to get fullname of customers in magento back-end server.
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
解決
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;
}
}
?>
所属していません magento.stackexchange