我想自定義操作添加到Magento的客戶網頁。添加新的客戶行動,Magento的客戶網
我有兩個模塊:一個叫經理這是一個客戶服務呼叫記錄有原因客戶來電列表,即「一般信息」,「訂單查詢」,「詐呼」。所有的原因都存儲在數據庫中。 「經理」模塊類似於將客戶分配給羣組的方式。
被稱爲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
)
)
));
我想不通爲什麼!
這正是我遇到的麻煩...感謝讓我知道我很接近... – user1704524 2013-03-07 19:32:48
記錄$ groups變量,你會看到結構,你就可以做同樣的事情,基本上它就像'$ collection = Model-> getCollection() - > filters/select/etc; $ collection = $ collection-> toOptionArray(); array_unshift($ collection,array('label'=>'','value'=>''));'因爲我不知道你的模型結構,我不能更精確。 – dagfr 2013-03-07 19:43:34
謝謝你們的幫助,如果你能稍微協助進一步,我會非常感激。這是我用作我的模塊的基礎http://www.excellencemagentoblog.com/magento-grid-serializer-admin-tabs-grid?facebook=1 – user1704524 2013-03-07 19:57:56