【问题标题】:How to add new attributes in Cutstomer Export CSV file in magento如何在 Magento 的 Cutstomer 导出 CSV 文件中添加新属性
【发布时间】:2014-10-10 06:49:58
【问题描述】:

我想在客户导出 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'
    ));

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

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

【问题讨论】:

    标签: magento


    【解决方案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');
    

    就是这样!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 2020-06-14
      • 2012-06-19
      • 2013-07-25
      相关资源
      最近更新 更多