0

私は持っていproduct idます。productidカスタム モジュールのデータベース フィールド名

カスタムモジュールのリストビューに製品名を表示したい。

これが私のコードです:

protected function _prepareColumns() {         
    $this->addColumn('productid', array(
        'header'    => Mage::helper('productpdf')->__('productid'),
        'align'     => 'center',
        'index'     => 'productid',
    ));
}
4

2 に答える 2

3

このためには、製品 ID から製品名を取得するために、コレクションを個別に作成する (または既存のコレクションに以下のクエリを含める) 必要があります。

あなたはこのようにすることができます

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

protected function _prepareColumns()
{


       $this->addColumn('productid', array(
       'header' => Mage::helper('productpdf')->__('productid'),
      'align'     =>'center',
     'index'     =>'productid',


      ));


         $this->addColumn('name', array(
        'header'    => Mage::helper('productpdf')->__('Name'),
        'width'     => '150',
        'index'     => 'name'
    ));


}

addAttributeToFilter('productid') では、製品 ID を渡す必要があります。これが機能することを願っています:-)

于 2013-10-08T07:21:27.967 に答える
1

大量のコードを使用する代わりに、model/productpdf.php ファイルに以下のコードを追加してください。

  /**
 * @param int $productId.
 * @return product name.
 */
public function getProductNameById($productId)
{
    $query_select = "SELECT value FROM `".Mage::getConfig()->getTablePrefix()."catalog_product_entity_varchar` WHERE
            entity_id = '".$productId."' AND `attribute_id` = 71";

    return $data = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($query_select); 

}

ファイルでこの関数を呼び出すだけです。

  $productNameArray = Mage::getModel('productpdf/productpdf')->getProductNameById($productId);

製品名を表示するための新しい列を追加します

  $this->addColumn('name', array(
    'header'    => Mage::helper('productpdf')->__('Name'),
    'width'     => '150',
    'index'     =>  $productNameArray[0]['value']
));

乾杯!!

于 2013-10-09T13:07:57.763 に答える