2016-11-23 99 views
0

我已經在互聯網上搜索了一個答案,其中包括許多SO問題,但沒有一個問題似乎爲我提供了我所需要的。在Magento中獲取客戶訂單中的訂單和發票網格

我有一個客戶自定義屬性()。我需要能夠在管理區域中的訂單發票網格中顯示此項。

我已經通過複製Mage_Adminhtml_Block_Orders_Grid到當地的游泳池,使用下面

$collection->getSelect() 
    ->join(
     'sales_flat_order_address', 
     'main_table.entity_id = sales_flat_order_address.parent_id', 
     array('email') 
    ); 

此代碼,顯然得到了客戶的電子郵件,只適用於該訂單網格。

任何人都可以幫我在這些表中獲得屬性?

使用CE 1.9。

UPDATE

我用下面的代碼加入_prepareCollection()列:

$gen_number_attr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('gen_number'); 
$collection->getSelect()->joinLeft(
    array(
     'table_customer_number' => $gen_number_attr->getBackend()->getTable()), 
     'main_table.customer_id = table_customer_number.entity_id AND table_customer_number.attribute_id = '.$gen_number_attr->getId(). ' AND table_customer_number.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(), 
     array(
      'customer_number' =>'table_customer_number.value' 
     ) 
    ); 

現在的問題是,當我試圖篩選我得到以下錯誤:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer_number' in 'where clause', query was: SELECT COUNT(*) FROM `sales_flat_order_grid` AS `main_table` 
INNER JOIN `sales_flat_order_address` ON main_table.entity_id = sales_flat_order_address.parent_id WHERE (`customer_number` LIKE '%123%') 

任何幫助,將不勝感激!

+0

任何幫助都將不勝感激。必須有人有一個想法 – Wildcard27

+0

轉介此http://magento.stackexchange.com/a/99000/45103 –

回答

2

訂購: - 複製默認的'app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.phtml'並放入'app/code/local/Mage/Adminhtml/Block/Sales /訂購/ Grid.phtml」。現在從它的新的本地目錄中打開Grid.php文件,看看下面的代碼塊小心:

protected function _prepareCollection() 
{ 
    $collection = Mage::getResourceModel($this->_getCollectionClass()); 
      /* adding term and condition section */ 
       $customerterm_conditionAttr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('term_condition'); 
       $collection->getSelect() 
          ->joinLeft(
           array('cusTerm_conditionTb' => $customerterm_conditionAttr->getBackend()->getTable()), 
           'main_table.customer_id = cusTerm_conditionTb.entity_id AND cusTerm_conditionTb.attribute_id = '.$customerterm_conditionAttr->getId(). ' AND cusTerm_conditionTb.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(), 
           array('term_condition' =>'cusTerm_conditionTb.value') 
          ); 
      /* end adding term and condition section */ 
    $this->setCollection($collection); 
    return parent::_prepareCollection(); 
} 
protected function _prepareColumns() 
    { 
     /* adding term and condition tab */ 
     $this->addColumn('term_condition', array(
      'header' => Mage::helper('sales')->__('Term and condition'), 
      'index' => 'term_condition', 
     )); 
     /* adding term and condition tab */ 
    } 

發票: - 複製默認的「應用程序/代碼/核心/法師/ Adminhtml /座/銷售/ Invoice/Grid.phtml'並將其放置在'app/code/local/Mage/Adminhtml/Block/Sales/Invoice/Grid.phtml'中。現在從其新的本地目錄中打開Grid.php文件,並仔細查看以下代碼塊:

protected function _prepareCollection() 
    { 
     $collection = Mage::getResourceModel($this->_getCollectionClass()); 
      /* adding term and condition section */ 
      $customerterm_conditionAttr = Mage::getSingleton('customer/customer')->getResource()->getAttribute('term_condition'); 
      $collection->getSelect() 
          ->joinLeft(
           array('sales_flat_order'), 
           'main_table.order_id = sales_flat_order.entity_id', 
           array('customer_id' =>'customer_id') 
          ); 
      $collection->getSelect() 
          ->joinLeft(
           array('cusTerm_conditionTb' => $customerterm_conditionAttr->getBackend()->getTable()), 
           'sales_flat_order.customer_id = cusTerm_conditionTb.entity_id AND cusTerm_conditionTb.attribute_id = '.$customerterm_conditionAttr->getId(). ' AND cusTerm_conditionTb.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(), 
           array('term_condition' =>'cusTerm_conditionTb.value') 
          );      
      /* end adding term and condition section */ 
     $this->setCollection($collection); 
     return parent::_prepareCollection(); 
    } 
protected function _prepareColumns() 
    { 
     /* adding term and condition tab */ 
     $this->addColumn('term_condition', array(
      'header' => Mage::helper('sales')->__('Term and condition'), 
      'index' => 'term_condition', 
     )); 
     /* adding term and condition tab */ 
    } 
+0

謝謝你的答案。這增加了列,但我無法過濾它。我得到以下'未找到列':'where子句'中的1054未知列'customer_number',查詢爲:SELECT COUNT(*)FROM sales_flat_order_grid AS main_table INNER JOIN sales_flat_order_address ON main_table.entity_id = sales_flat_order_address.parent_id WHERE(customer_number LIKE' %cst%')' – Wildcard27

+0

請使用給定的鏈接獲取過濾代碼。 https://docs.google.com/document/d/1yGrOQ8A2zpLG8-KWj7kxiIQLXp4ESgEzWE-Jn95BO6k/edit –

+1

這工作!感謝您的幫助! – Wildcard27