2016-08-02 25 views
0

商品「sellable_in_market」のカスタム属性を作成しました。それを製品グリッドに表示しようとしました。しかし、その列は空です。しかし、私がYES/NOでフィルタリングすると、それが表示されます。どのようにグリッド内のフィルタを使用して属性値( "sellable_in_market")を表示するか?何をすべきかわからない。以下は私のコードです。カタログ製品グリッドのカスタム属性値をマゼンタで表示するにはどうすればよいですか?

アドバンスありがとうございました。

protected function _prepareCollection() 
     { 
      parent::_prepareCollection(); 
      $collection = $this->getCollection(); 
      $store = $this->_getStore(); 
      if ($store->getId()) { 
       $collection = $collection->joinAttribute(
       'sellable_in_market', 
       'catalog_product/sellable_in_market', 
       'entity_id', 
       null, 
       'left', 
       $store->getId() 
       ); 
      } 
      else { 

       $collection = $collection->joinAttribute('sellable_in_market', 'catalog_product/sellable_in_market', 'entity_id', null, 'left'); 
      } 
     $this->setCollection($collection); 
      return $this; 
     } 

     protected function _prepareColumns() 
     { 
      $this->addColumnAfter('sellable_in_market', 
      array(
      'header'=> Mage::helper('catalog')->__('Resellable'), 
      'width' => '60px', 
      'index' => 'sellable_in_market', 
      'sortable' => true, 
      'type' => 'options', 
      'options' => array("1" => 'Yes', "0" => 'No'), 
      ), 
      'type' 
      ); 
      parent::_prepareColumns(); 

     } 

「再販売可能」の列は空です。しかし、yes/noでフィルタすると表示されます。 デフォルトでグリッドにカスタム値を表示する方法はありますか?

+0

商品の一覧ページに商品の配列を印刷しましたか? –

+0

はい、そこには問題ありません。私はそこに "sellable_in_market"を見ることができます。 –

+0

管理グリッドであなたのコレクションの価値を得ていますか? –

答えて

0

$ this-> setCollection($ collection)行の前に、製品グリッドの_prepareCollection関数で Mage_Adminhtml_Block_Catalog_Product_Gridを選択するコードを以下に追加してください。

$attributeCode = 'qc_status';//here your attribute code 
     $collection->joinAttribute($attributeCode, 'catalog_product/'.$attributeCode, 'entity_id', null, 'left'); 
     $collection->addAttributeToSelect($attributeCode); 

グリッドの_prepareColumns関数の列のコードです。

$attributeCodeConfig ='qc_status';//Your attribute code... 

     $attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $attributeCodeConfig); 

     $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId); 
     $attributeData = $attribute->getData(); 
     $frontEndLabel = $attributeData['frontend_label']; 

     $attributeOptions = $attribute->getSource()->getAllOptions(); 
     $b = new Mage_Catalog_Model_Resource_Eav_Attribute(); 
     $attributeOptions2 = array(); 
     foreach ($attributeOptions as $value) { 
      if(!empty($value['value'])) { 
       $attributeOptions2[$value['value']] = $value['label']; 
      } 

     } 


     if(count($attributeOptions2) > 0) { 
      $this->addColumn($attributeCodeConfig, 
       array(
        'header'=> Mage::helper('catalog')->__($frontEndLabel), 
        'width' => '80px', 
        'index' => $attributeCodeConfig, 
        'type' => 'options', 
        'options' => $attributeOptions2, 

      )); 
     } else { 
      $this->addColumn($attributeCodeConfig, 
       array(
        'header'=> Mage::helper('catalog')->__($frontEndLabel), 
        'width' => '80px', 
        'index' => $attributeCodeConfig, 

      )); 
     } 
関連する問題