我正在尝试将自定义操作添加到Magento中的Customer Grid页面。
我有两个模块:一个叫做Manager,它是一个客户服务呼叫记录,其中包含客户呼叫的原因列表,即“常规信息”,“订单查询”,“恶作剧呼叫”。所有原因都存储在数据库中。 “经理”模块类似于将客户分配到群组的工作方式。
第二个模块名为Customergrid,它扩展了Mage_Adminhtml_Block_Customer_Grid
这是我在下拉菜单中添加了一个名为“添加到呼叫记录”的选项。我希望这可以通过类似的方式工作,如何将客户添加到“组”中。如果我从网格列表中选择一个客户并选择“添加到呼叫日志”,则需要从另一个下拉列表中选择(与添加到客户组一样)“原因”并单击“保存”。
问题:
我需要找到一种方法来显示下拉列表中的原因列表。
以下是来自customergrid模块的Grid.php的代码:
<?php
class Module_Customergrid_Block_Adminhtml_Customer_Grid extends Mage_Adminhtml_Block_Customer_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');
$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'),
'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')
));
$this->getMassactionBlock()->addItem('manager_grid', array(
'label' => Mage::helper('manager')->__('Add to call log'),
'url' => $this->getUrl('*/*/massAssignGroup'),
'additional' => array(
'visibility' => array(
'name' => 'reason',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('manager')->__('Reason'),
'values' => $data
)
)
));
$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()));
}
}
任何人都可以告诉我,如果我以正确的方式进行此操作,因为我无法在第二个下拉字段中显示“原因”列表。我是新手来定制Magento管理员,所以请原谅我缺乏知识。
如果我尝试向数组添加选项,我会得到一个空屏幕:
$collection = $this->helper('manager')->getCollection()->toOptionArray();
array_unshift($manager, array('label'=> '','value'=>''));
$this->getMassactionBlock()->addItem('manager', array(
'label' => Mage::helper('manager')->__('Add to call log'),
'url' => $this->getUrl('*/*/massAssignManager'),
'additional' => array(
'visibility' => array(
'name' => 'manager',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('manager')->__('Reason'),
'values' => $manager
)
)
));
我无法弄明白为什么!!
答案 0 :(得分:1)
你正在做一些好事,只有一件事情可以用于额外的下拉菜单:'values'=&gt; $的数据。数据未定义。
查看组以查看序列化选项以启用此第二个下拉列表的工作原理
$groups = $this->helper('customer')->getGroups()->toOptionArray();
array_unshift($groups, array('label'=> '', 'value'=> ''));
你需要类似于在数组中获取选项的东西。