2014-10-10 35 views
1

我想在Customer Export CSV文件中添加新屬性。我的字段是出生日期和性別。如何在Cutteromer中添加新屬性在magento中導出CSV文件

我已經添加了下面的代碼在代碼/核心/法師/ Adminhtml /座/客戶/ Grid.php

$this->addColumn('dob', array(
     'header' => Mage::helper('customer')->__('Date of Birth'), 
     'type'  => 'datetime', 
     'align'  => 'center', 
     'index'  => 'dob', 
     'gmtoffset' => true 
    )); 
$this->addColumn('gender', array(
     'header' => Mage::helper('customer')->__('Gender'), 
     'index'  => 'gender' 
    )); 

在管理面板下的管理客戶也顯示了相同的名稱,但新的空文件數據,並在CSV文件中添加了兩個字段的標題,但字段爲空。

如何在magento中的客戶導出文件中添加新字段?

回答

1

,而不是你的性別代碼,把這個:

$genders = $this->_getGenderOptions(); 
$this->addColumn('gender', array(
    'header' => Mage::helper('customer')->__('Gender'), 
    'index'  => 'gender', 
    'type'  => 'options', 
    'options' => $genders 
)); 

然後,在網格類中創建新的方法:

private function _getGenderOptions() 
{ 
    $options = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions(); 
    $array = array(); 

    foreach ($options as $option) 
    { 
     if($option['label'] == "") 
      continue; 

     $array[$option['value']] = $option['label']; 
    } 

    return $array; 
} 

,並在方法

protected function _prepareCollection(); 

通過添加加載收藏:

->addAttributeToSelect('dob') 
->addAttributeToSelect('gender') 

它應該看起來像:

$collection = Mage::getResourceModel('customer/customer_collection') 
     ->addNameToSelect() 
     ->addAttributeToSelect('email') 
     ->addAttributeToSelect('dob') // new code 
     ->addAttributeToSelect('gender') // new code 
     ->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'); 

,這就是它!

+0

謝謝作品幫我 – 2014-10-10 07:50:20

+0

歡迎您! – 2014-10-10 07:51:06