2012-04-30 21 views
2

Reports-> Products Orderedグリッドに新しい製品属性を追加しようとしています。 「色」と「サイズ」は、彼らが代わりにオプションのテキストのオプション値を示している理由thatsのドロップダウン属性れProductレポートグリッドにドロップダウン属性を追加Magento

protected function _prepareColumns() 
    { 
     $this->addColumn('created_at', array(
      'header' =>Mage::helper('reports')->__('Create At'), 
      'index'  =>'created_at' 
     )); 
     $this->addColumn('sku', array(
      'header' =>Mage::helper('reports')->__('sku'), 
      'index'  =>'sku' 
     )); 
     $this->addColumn('name', array(
      'header' =>Mage::helper('reports')->__('Product Name'), 
      'index'  =>'name' 
     )); 
     $this->addColumn('color', array(
      'header' =>Mage::helper('reports')->__('Color'), 
      'index'  =>'color', 
      'type'  => 'options' 
     )); 
     $this->addColumn('size', array(
      'header' =>Mage::helper('reports')->__('Size'), 
      'index'  =>'size' 
     )); 
     $this->addColumn('price', array(
      'header' =>Mage::helper('reports')->__('Price'), 
      'width'  =>'120px', 
      'type'  =>'currency', 
      'currency_code' => $this->getCurrentCurrencyCode(), 
      'index'  =>'price' 
     )); 

     $this->addColumn('ordered_qty', array(
      'header' =>Mage::helper('reports')->__('Quantity Ordered'), 
      'width'  =>'120px', 
      'align'  =>'right', 
      'index'  =>'ordered_qty', 
      'total'  =>'sum', 
      'type'  =>'number' 
     )); 

     $this->addExportType('*/*/exportSoldCsv', Mage::helper('reports')->__('CSV')); 
     $this->addExportType('*/*/exportSoldExcel', Mage::helper('reports')->__('Excel')); 

     return parent::_prepareColumns(); 
    } 

問題がある:私は /app/code/local/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.phpをコピーして、このような属性を追加します。グリッド内のドロップダウン属性のText値を表示する方法は?あなたが提案し、それが今のブランクカラー列を示すよう

EDIT 1

ありがとうBOOMERは...私は私のGrid.phpを変更しました。私が何をしたかHERESに:

protected function _prepareCollection() 
    { 
     $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('color'); 

     parent::_prepareCollection(); 
     $this->getCollection() 
      ->initReport('reports/product_sold_collection'); 
     return $this; 
    } 

    /** 
    * Prepare Grid columns 
    * 
    * @return Mage_Adminhtml_Block_Report_Product_Sold_Grid 
    */ 
    protected function _prepareColumns() 
    { 
     $colors = Mage::getResourceModel('eav/entity_attribute_option_collection') 
      ->setAttributeFilter(80) // set your attribute ID here 
      ->setStoreFilter() 
      ->load() 
      ->toOptionHash('option_id', 'value'); 

     $this->addColumn('created_at', array(
      'header' =>Mage::helper('reports')->__('Create At'), 
      'index'  =>'created_at' 
     )); 
     $this->addColumn('sku', array(
      'header' =>Mage::helper('reports')->__('sku'), 
      'index'  =>'sku' 
     )); 
     $this->addColumn('name', array(
      'header' =>Mage::helper('reports')->__('Product Name'), 
      'index'  =>'name' 
     )); 
     $this->addColumn('color', array(
      'header' =>Mage::helper('reports')->__('Color'), 
      'index'  =>'color', 
      'type'  => 'options', 
      'options' => $colors 
     )); 
} 
+0

詳細:重複空白のオプションを避けるための条件ならば、私は通常、すなわち、でのforeach内のステートメントを置き換える次

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color'); $colors = array(); foreach($attribute->getSource()->getAllOptions(true, true) as $option) { $colors[$option['value']] = $option['label']; } 

であなたの$colors =アクションを交換してみてください属性のデータ私は 'zend_debug :: dump($ colors);'と 'zend_debug :: dump($ collection);'を使ってデータが確実に存在するようにします。 – B00MER

答えて

3

まずあなたがたとえば、あなたの_prepareCollection()方法で選択する属性を追加していることを確認:

$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('color');

そして、あなたの_prepareColumns()以内にコレクションを定義する必要があります

$colors = Mage::getResourceModel('eav/entity_attribute_option_collection') 
      ->setAttributeFilter(15) // set your attribute ID here 
      ->setStoreFilter() 
      ->load() 
      ->toOptionHash('option_id', 'value'); 

必ず属性IDを設定してください。そして、そのようなあなたのaddColumnsで、このコレクションのリストを使用します。

$this->addColumn('color', array(
      'header' =>Mage::helper('reports')->__('Color'), 
      'index'  =>'color', 
      'type'  => 'options', 
      'options' => $colors 
     )); 

ホープ、このことができます!

+0

レスポンスありがとうございますが、色の列が空白になっています。あなたが提案したとおりに変更を加えました。問題の「EDIT 1」を参照してください。 – Hum

0

少なくともカスタム属性の場合は、別の方法を使用することをお勧めします。おそらく、あなたのコレクションがありませんよりも

if ($option['label']) 
    $sets[$option['value']] = $option['label']; 
関連する問題