2016-11-23 70 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