2014-02-20 2 views
1

에 표시 할 사용자 정의 고객 속성 속성 :젠토 사용자 정의 고객은 내가 만든 그리드

$installer->addAttribute('customer', 'forum_username', array(
    'type' => 'varchar', 
    'input' => 'text', 
    'label' => 'Forum username', 
    'global' => 1, 
    'visible' => 1, 
    'required' => 0, 
    'user_defined' => 1, 
    'default' => '', 
    'visible_on_front' => 1, 
)); 

지금 내가 Mage_Adminhtml_Block_Customer_Grid 드리고 있습니다 고객 그리드에 보여주고 싶은 및 열 addet :

protected function _prepareColumns() 
{ 
    $this->addColumnAfter('forum_username', array(
     'header' => Mage::helper('customization')->__('Forum user name'), 
     'index'  => 'forum_username', 
     'type' => 'text' 
    ),'email'); 
    return parent::_prepareColumns(); 
} 

열이 표에 표시되지만 속성 값을 가져올 수 없으며 우편 번호를 가져 오는 데 joinAttribute()를 사용하여 값을 가져 오는 방법을 모르겠다.

http://magentocommerces.wordpress.com/2012/04/17/addattributetosortaddexpressionattributetoselect-joinattribute/ 이 함께 제공 :
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left') 

내가이 페이지에서 어떻게 작동하는지 이해하기 위해 노력했다

->joinAttribute('forum_username', 'customer/forum_username', 'attribute_set_id', null, 'left') 

을하지만 그렇지

답변

1

Never84를 작동 않습니다,이 코드 addAttributeToSelect('forum_username')를 추가하십시오 this-

protected function _prepareCollection() 
       { 
        $collection = Mage::getResourceModel('customer/customer_collection') 
         ->addNameToSelect() 
         ->addAttributeToSelect('email') 
         ->addAttributeToSelect('created_at') 
     ->addAttributeToSelect('forum_username') 
         ->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(); 
    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection(); 
       } 



protected function _prepareColumns() 
    { 
     $this->addColumn('entity_id', array(
      'header' => Mage::helper('customer')->__('ID'), 
      'width'  => '50px', 
      'index'  => 'entity_id', 
      'type' => 'number', 
     )); 
     /*$this->addColumn('firstname', array(
      'header' => Mage::helper('customer')->__('First Name'), 
      'index'  => 'firstname' 
     )); 
     $this->addColumn('lastname', array(
      'header' => Mage::helper('customer')->__('Last Name'), 
      'index'  => 'lastname' 
     ));*/ 
     $this->addColumn('name', array(
      'header' => Mage::helper('customer')->__('Name'), 
      'index'  => 'name' 
     )); 
     $this->addColumn('email', array(
      'header' => Mage::helper('customer')->__('Email'), 
      'width'  => '150', 
      'index'  => 'email' 
     )); 
     $this->addColumn('forum_username', array(
      'header' => Mage::helper('customer')->__('Forum user name'), 
      'width'  => '50px', 
      'index'  => 'forum_username', 
      'type' => 'text', 
     )); 

     $groups = Mage::getResourceModel('customer/group_collection') 
      ->addFieldToFilter('customer_group_id', array('gt'=> 0)) 
      ->load() 
      ->toOptionHash(); 



    $this->addColumn('group', array(
      'header' => Mage::helper('customer')->__('Group'), 
      'width'  => '100', 
      'index'  => 'group_id', 
      'type'  => 'options', 
      'options' => $groups, 
     )); 

     $this->addColumn('Telephone', array(
      'header' => Mage::helper('customer')->__('Telephone'), 
      'width'  => '100', 
      'index'  => 'billing_telephone' 
     )); 

     $this->addColumn('billing_postcode', array(
      'header' => Mage::helper('customer')->__('ZIP'), 
      'width'  => '90', 
      'index'  => 'billing_postcode', 
     )); 

     $this->addColumn('billing_country_id', array(
      'header' => Mage::helper('customer')->__('Country'), 
      'width'  => '100', 
      'type'  => 'country', 
      'index'  => 'billing_country_id', 
     )); 

     $this->addColumn('billing_region', array(
      'header' => Mage::helper('customer')->__('State/Province'), 
      'width'  => '100', 
      'index'  => 'billing_region', 
     )); 

     $this->addColumn('customer_since', array(
      'header' => Mage::helper('customer')->__('Customer Since'), 
      'type'  => 'datetime', 
      'align'  => 'center', 
      'index'  => 'created_at', 
      'gmtoffset' => true 
     )); 

     if (!Mage::app()->isSingleStoreMode()) { 
      $this->addColumn('website_id', array(
       'header' => Mage::helper('customer')->__('Website'), 
       'align'  => 'center', 
       'width'  => '80px', 
       'type'  => 'options', 
       'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true), 
       'index'  => 'website_id', 
      )); 
     } 

     $this->addColumn('action', 
      array(
       'header' => Mage::helper('customer')->__('Action'), 
       'width'  => '100', 
       'type'  => 'action', 
       'getter' => 'getId', 
       'actions' => array(
        array(
         'caption' => Mage::helper('customer')->__('Edit'), 
         'url'  => array('base'=> '*/*/edit'), 
         'field'  => 'id' 
        ) 
       ), 
       'filter' => false, 
       'sortable' => false, 
       'index'  => 'stores', 
       'is_system' => true, 
     )); 

     $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV')); 
     $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML')); 
     return parent::_prepareColumns(); 
    } 

같은 그리드는 또한 ---

다음과 같이 : 설치 프로그램
<?php 
    $installer = $this; 
    $installer->startSetup(); 

    /*Create Artist of the month */ 
    $installer->addAttribute('customer', 'forum_username', array(
     'input' => 'text', 
     'type' => 'varchar', 
     'label' => 'Forum Username', 
     'visible' => 1, 
     'required' => 0, 
     'user_defined' => 1, 
    )); 


    $attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "forum_username"); 
    $used_in_forms= 

array(); 

$used_in_forms[]="adminhtml_customer"; 
     $attribute->setData("used_in_forms", $used_in_forms) 
     ->setData("is_used_for_customer_segment", true) 
     ->setData("is_system", 0) 
     ->setData("is_user_defined", 1) 
     ->setData("is_visible", 1) 
     ->setData("sort_order", 100) 
     ; 
     $attribute->save(); 

$installer->endSetup(); 
+0

Never84, 작동합니까 ?? –

+0

고마워요. 작동하지 않습니다. 처음 시도한 내용이 잘못되었습니다. -> addAttributeToSelect ('forum_username') – Marko

+0

희망 사항은 instraller에서 문제가 될 것입니다. –

관련 문제