如何将自定义属性添加到客户导出csv

时间:2014-09-18 07:08:21

标签: magento grid export magento-1.7

我有4个自定义attrubute for customer.i想在export.i中将它添加到网格中仅用于导出但它似乎没有work.csv创建但数据没有填写csv。 下面是grid.php中用于csv导入的代码。

       if ($this->_isExport) { 
     $this->addColumn('contact_job_title', array(
    'header' => Mage::helper('customer')->__('Contact Job Title'),
    'index'  => 'contact_job_title',
));
 $this->addColumn('contact_seq_no', array(
    'header' => Mage::helper('customer')->__('Contact Seq No'),
    'index'  => 'contact_seq_no',
));
$this->addColumn('debtor_acc_no', array(
    'header' => Mage::helper('customer')->__('Debtor Acc No'),
    'index'  => 'debtor_acc_no',
));
$this->addColumn('debtor_api_key', array(
    'header' => Mage::helper('customer')->__('Debtor Api Key'),
    'index'  => 'debtor_api_key',
));
    }

任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:1)

好的,我找到了答案

只需添加要在

中选择的属性
protected function _prepareCollection()
{
    $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('email')
         ->addAttributeToSelect('debtor_api_key') /* added attribute */
         ->addAttributeToSelect('contact_job_title')  /* added attribute */
         ->addAttributeToSelect('contact_seq_no')  /* added attribute */
         ->addAttributeToSelect('creditstatus')  /* added attribute */
         ->addAttributeToSelect('debtor_acc_no')  /* added attribute */
        ->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();
}

和addcolumn仅用于导出

if ($this->_isExport) { 
        $this->addColumn('debtor_api_key', array(
            'header' => Mage::helper('customer')->__('Debtor Api Key'),
            'index'  => 'debtor_api_key',
        ));
        $this->addColumn('contact_job_title', array(
            'header' => Mage::helper('customer')->__('Contact Job Title'),
            'index'  => 'contact_job_title',
        ));
        $this->addColumn('contact_seq_no', array(
            'header' => Mage::helper('customer')->__('Contact Seq No'),
            'index'  => 'contact_seq_no',
        ));
        $this->addColumn('creditstatus', array(
            'header' => Mage::helper('customer')->__('Creditstatus'),
            'index'  => 'creditstatus',
        ));
        $this->addColumn('debtor_acc_no', array(
            'header' => Mage::helper('customer')->__('Debtor Acc No'),
            'index'  => 'debtor_acc_no',
        ));
    }