2015-04-22 71 views
2

我使用優惠券代碼在訂單網格中添加到列時出現問題。我在http://www.atwix.com/magento/customize-orders-grid/上使用了教程。magento在訂單網格中添加使用優惠券代碼的列

我複製Grid.php從/app/code/core/Mage/Adminhtml/Block/Sales/Order//app/code/local/Mage/Adminhtml/Block/Sales/Order/並添加以下代碼:函數_prepareColumns()

$select->join('sales_flat_order', '`sales_flat_order`.entity_id = `main_table`.entity_id',array('coupon_code')) 

的功能_prepareCollection(),並添加列:

$this->addColumn('coupon_code', array(
     'header' => Mage::helper('sales')->__('Coupon Coded'), 
      'index' => 'coupon_code' 
    )); 

但在網頁銷售/訂單在管理員不顯示任何東西。有誰知道什麼時候會成爲問題?

謝謝你的意見/想法。

+0

你的代碼是正確的,請檢查app/etc/local.xml中是否啓用了本地模塊並嘗試清空緩存 –

+0

謝謝。這可能是緩存,現在是一個新的優惠券代碼列,但如果我按特定的順序排序。向我顯示此錯誤SQLSTATE [23000]:完整性約束違規:1052 Where子句中的列'increment_id'不明確 –

回答

0

嘗試更換您已加入到_prepareCollection()函數與下面的一個代碼:

$adapter = $collection->getResource()->getReadConnection(); 
    $subSelect = $adapter->select() 
     ->from(array('sales_flat_order'), array('entity_id', 'coupon_code')); 

    $collection->getSelect() 
     ->join(array('order' => $subSelect), '`order`.entity_id = `main_table`.entity_id',array('coupon_code')); 
0

現在是用優惠券代碼的新列,但如果我通過特定的順序做排序。給我這個錯誤SQLSTATE [23000]:完整性約束違規:1052列在where子句是曖昧

+0

您是否嘗試過我們以前的答案中描述的解決方案? – MagestyApps

+0

是的,我試過了,並顯示相同的錯誤。 –

1
protected function _prepareCollection() { 
     $collection = Mage::getResourceModel($this->_getCollectionClass()); 
     $collection->getSelect()->join('sales_flat_order', 
       'main_table.entity_id = sales_flat_order.entity_id', 
       array('coupon_code' => 'coupon_code'));   
     $this->setCollection($collection); 
     //For sort 
     Mage_Adminhtml_Block_Widget_Grid::_prepareCollection(); 
} 
+0

我可以證實這一個作品! –

0

如果你有不明確的列錯誤「increment_id」,試試這個:

protected function _addColumnFilterToCollection($column) 
{ 
    if ($this->getCollection()) { 
     $field = ($column->getFilterIndex()) ? $column->getFilterIndex() : $column->getIndex(); 
     $field = 'main_table.'.$field; 
     if ($column->getFilterConditionCallback()) { 
      call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column); 
     } else { 
      $cond = $column->getFilter()->getCondition(); 
      if ($field && isset($cond)) { 
       $this->getCollection()->addFieldToFilter($field , $cond); 
      } 
     } 
    } 
    return $this; 
}