如何在Magento中的Cutstomer导出CSV文件中添加新属性

时间:2014-10-10 06:49:58

标签: magento

我想在客户导出CSV文件中添加新属性。我的领域是出生日期和性别。

我在 code / core / Mage / Adminhtml / Block / Customer / 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'
    ));

在manage customer下的管理面板中,它显示具有相同名称但空数据的新文件,并且在CSV文件中,它还为这两个字段添加了标题,但字段为空。

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

1 个答案:

答案 0 :(得分:1)

而不是您的性别代码,请输入:

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

然后,在Grid类中创建新方法:

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');

那就是它!

相关问题