내 관리자 사이드 고객 그리드에서 내가 열리는 이름과 성을 필요로하는 열정과 시간이있는 고객이 있습니다. 이미 magento 코어에서 완료되었지만 일부 고객은 이름을 인쇄해야합니다. 내 Grid.php 좀 봐, 내가 '네임'catenation에서 성을 벗을 필요하지만 콜렉션에서 내 열 정렬 작업을 제거합니다.고객 그리드에서 사용자 정의 열 정렬 순서
<?php
class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('customerGrid');
$this->setUseAjax(true);
$this->setDefaultSort('entity_id');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->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');
/*foreach($collection as $customer){
preg_match("/[A-z| ]*//*", $customer->getName(), $name);
$customer->setName($name[0]);
unset($name);
}*/
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('entity_id', array(
'header' => Mage::helper('customer')->__('ID'),
'width' => '50px',
'index' => 'entity_id',
'type' => 'number',
));
/*
$this->addColumn('firstname', array(
'header' => Mage::helper('customer')->__('First Name'),
'index' => 'firstname'
));
$this->addColumn('lastname', array(
'header' => Mage::helper('customer')->__('Last Name'),
'index' => 'lastname'
));
*/
$this->addColumn('name', array(
'header' => Mage::helper('customer')->__('Name'),
'sortable' => true,
'index' => 'name'
));
$this->addColumn('email', array(
'header' => Mage::helper('customer')->__('Email'),
'width' => '150',
'index' => 'email'
));
$groups = Mage::getResourceModel('customer/group_collection')
->addFieldToFilter('customer_group_id', array('gt'=> 0))
->load()
->toOptionHash();
$this->addColumn('group', array(
'header' => Mage::helper('customer')->__('Group'),
'width' => '100',
'index' => 'group_id',
'type' => 'options',
'options' => $groups,
));
$this->addColumn('Telephone', array(
'header' => Mage::helper('customer')->__('Telephone'),
'width' => '100',
'index' => 'billing_telephone'
));
$this->addColumn('billing_postcode', array(
'header' => Mage::helper('customer')->__('ZIP'),
'width' => '90',
'index' => 'billing_postcode',
));
$this->addColumn('billing_country_id', array(
'header' => Mage::helper('customer')->__('Country'),
'width' => '100',
'type' => 'country',
'index' => 'billing_country_id',
));
$this->addColumn('billing_region', array(
'header' => Mage::helper('customer')->__('State/Province'),
'width' => '100',
'index' => 'billing_region',
));
$this->addColumn('customer_since', array(
'header' => Mage::helper('customer')->__('Customer Since'),
'type' => 'datetime',
'align' => 'center',
'index' => 'created_at',
'gmtoffset' => true
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('website_id', array(
'header' => Mage::helper('customer')->__('Website'),
'align' => 'center',
'width' => '80px',
'type' => 'options',
'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
'index' => 'website_id',
));
}
$this->addColumn('action',
array(
'header' => Mage::helper('customer')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('customer')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
$this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
return parent::_prepareColumns();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('customer');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('customer')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('customer')->__('Are you sure?')
));
$this->getMassactionBlock()->addItem('newsletter_subscribe', array(
'label' => Mage::helper('customer')->__('Subscribe to Newsletter'),
'url' => $this->getUrl('*/*/massSubscribe')
));
$this->getMassactionBlock()->addItem('newsletter_unsubscribe', array(
'label' => Mage::helper('customer')->__('Unsubscribe from Newsletter'),
'url' => $this->getUrl('*/*/massUnsubscribe')
));
$groups = $this->helper('customer')->getGroups()->toOptionArray();
array_unshift($groups, array('label'=> '', 'value'=> ''));
$this->getMassactionBlock()->addItem('assign_group', array(
'label' => Mage::helper('customer')->__('Assign a Customer Group'),
'url' => $this->getUrl('*/*/massAssignGroup'),
'additional' => array(
'visibility' => array(
'name' => 'group',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('customer')->__('Group'),
'values' => $groups
)
)
));
return $this;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=> true));
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
}
} 내가 아는
그 길을 잘못하지만, 단지 이름을 얻을 수 있고 다른 방법이 없습니다. 하지만 이제는 그리드 작업에서 컬럼 정렬에 대한 내 정렬합니다. 정렬 작업이 필요해. 내 _prepareCollection()에서이 세 줄을 제거하면 잘 작동하지만 너무 필요하고 내 정렬 작동하지 않습니다. 나는 누군가가 도울 수있는 이것과 미쳤다 ???
타이가 있습니다.
타이를
->addAttributeToSelect('firstname')
에 추가 한 다음 prepareColumns 기능에 열을 추가해야한다,하지만 난 고객의 한 종류가 다른 내 경우는은을 표시하지 않은 경우 성,하지만 고객의 어떤 종류의 나는 이름 + 성이 필요합니다. 하나의 '이름'열을 사용하고 있으며 잘 작동하며 정렬을 수행합니다. 그러나, 나는이 컬렉션에 성을 위해 무엇을 보여주고 변경하고 싶지 않으면 그리드에서 작업 정렬을 중지합니다. 그리드에 어떻게 정렬 및 필드가 사용해야하는지 어떻게 말합니까? 내 Grid.php 살펴보기 : – Guerra왜 두 개의 다른 기능을 하나의 열에 구h 주려고하는지 알지 못합니다. 두 개의 열이 있으면 원하는 것을 정렬 할 수 있습니다. 단일 열을 실제로 원한다면 special_name에 대한 새 특성을 만든 다음 고객 _before_save 이벤트에서이 값을 업데이트하여 해당 유형의 고객에게 맞는 것이 무엇이든되도록하는 것이 가장 좋습니다. –
알다시피, 이런 식으로 나는 결코 일하지 않으려 고 노력하고 있습니까? 당신이 말하는 것은 의미가 있습니다. 그러나 그 프로젝트에 이런 일이 일어나지 않도록주의를 기울여야합니다. 그러나 나는 그것에 대해 생각할 것이다. Ty – Guerra