2013-04-17 151 views
1

我正嘗試使用Grid.php添加在管理中訂單網格的產品。將訂單項添加到Magento中的訂單網格

app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php 

我已經爲此視圖添加了另一個客戶屬性。當我添加產品列表時,發現的訂單數始終設置爲1,並且不會讓我進入訂單的下一頁。

enter image description here

這是我已成功地添加代碼。

protected function _prepareCollection() 
{ 
    $collection = Mage::getResourceModel($this->_getCollectionClass()); 
    $collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('name' => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.name SEPARATOR ", ")'))); 
    $collection->getSelect()->group('entity_id'); 
    $collection->getSelect()->joinLeft(
       array('cev' => 'customer_entity_varchar'), 
       '(main_table.customer_id = cev.entity_id AND cev.attribute_id = 141 AND main_table.customer_id IS NOT NULL)', 
       array(
        'admin_number' => 'cev.value', 
       ) 
      ); 

    $this->setCollection($collection); 
    return parent::_prepareCollection(); 
} 

    $this->addColumn('admin_number', array(
      'header' => Mage::helper('sales')->__('Admin Number'), 
      'filter_index' => 'cev.value', 
      'index' => 'admin_number' 
    )); 

$this->addColumn('name', array(
     'header' => Mage::helper('Sales')->__('Products'), 
     'width'  => '100px', 
     'index'  => 'name', 
     'type'  => 'text', 

    )); 

希望有人能幫我看看有什麼不對。

回答

2
protected function _prepareCollection() 
     { 
    $userArray = Mage::getSingleton('admin/session')->getData(); 
    $user = Mage::getSingleton('admin/session'); 
    $userId = $user->getUser()->getUserId(); 

    $connection = Mage::getSingleton('core/resource')->getConnection('core_read'); 
    $sql  = "Select * from sales_flat_order_grid as sss, junaidbhura_jbmarketplace_products as vitem, sales_flat_order_item as item WHERE vitem.product_id = item.product_id and sss.entity_id = item.order_id and vitem.user_id = $userId"; 
    $rows  = $connection->fetchAll($sql); //fetchRow($sql), fetchOne($sql),... 
    //Zend_Debug::dump($rows); 
    $pk = 0; 
    foreach($rows as $value){ 
    $pkorder[] = $rows[$pk]['order_id']; 
    $pk++; 
    } 

    //print_r($pkorder); 


    //print_r($userId); 
    //die; 

      $collection = Mage::getResourceModel($this->_getCollectionClass()); 
      if($userId == 1){ }else{ 
      $collection->addFieldToFilter('entity_id', array('in' => array($pkorder))); 
      } 
      $this->setCollection($collection); 
      return parent::_prepareCollection(); 
     } 
+0

你能解釋一下你從原始代碼改變了什麼嗎? –

+0

$ rows = $ connection-> fetchAll($ sql); // fetchRow($ sql),fetchOne($ sql),... // Zend_Debug :: dump($ rows); $ pk = 0; foreach($ rows as $ value){ $ pkorder [] = $ rows [$ pk] ['order_id']; $ pk ++; } – user2185477

相關問題