如何在magento中的Cutstomer导出CSV文件中添加新属性
我想在客户导出CSV文件中添加新属性。我的字段是出生日期和性别 我在code/core/Mage/Adminhtml/Block/Customer/Grid.php中添加了以下代码如何在magento中的Cutstomer导出CSV文件中添加新属性,magento,Magento,我想在客户导出CSV文件中添加新属性。我的字段是出生日期和性别 我在code/core/Mage/Adminhtml/Block/Customer/Grid.php中添加了以下代码 $this->addColumn('dob', array( 'header' => Mage::helper('customer')->__('Date of Birth'), 'type' => 'datetime', 'al
$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的客户导出文件中添加新字段?将以下内容替换为您的性别代码:
$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');
就这样