2017-06-30 111 views
0

嘗試過濾管理網格以查看特定產品上的銷售歷史記錄,但在嘗試按帳單過濾時收到以下錯誤名稱:Magento:SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'billing_name'

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'billing_name' in 'where clause'

這裏是我使用的是什麼:

protected function _prepareCollection() { 
    $productId = $this->getProduct()->getId(); 
    $ordersId = $this->getOrderIds($productId); 

    $collection = mage::getModel('sales/order') 
       ->getCollection() 
       ->addFieldToFilter('main_table.entity_id', array('in' => $ordersId)) 
       ->join('sales/order_address', '`sales/order_address`.entity_id=billing_address_id', array('billing_name' => "concat(firstname, ' ', lastname)")); 

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

然後添加格列記帳名稱:

protected function _prepareColumns() { 

    $this->addColumn('billing_name', array(
     'header' => Mage::helper('AdvancedStock')->__('Bill to Name'), 
     'index' => 'billing_name', 
     'sortable' => true 
    )); 

return parent::_prepareColumns(); 
} 

該列將正確返回包含產品的訂單中的所有開票名稱,我只是無法按名稱過濾該列。有任何想法嗎?

+0

您已將計費名稱添加到模型,但不是數據庫?當您查看'sales_flat_order'(或者它是否是'sales_flat_order_address')表時,它是否存在? – CD001

+0

@ CD001我相信它在'sales_flat_order_address'中,雖然我沒有訪問phpMyAdmin來檢查表格 – AJ47

回答

1

magento sales_flat_order和sales_flat_order_order_address表將不具有列billing_name。
您可以使用sales_flat_order_grid表而不是sales_flat_order_address爲獲得這樣的billing_name,

$collection = Mage::getModel('sales/order') 
        ->getCollection() 
        ->addFieldToFilter('main_table.entity_id', array('in' => $ordersId)) 
        ->join('sales/order_grid', '`sales/order_grid`.entity_id=main_table.entity_id', array('billing_name' => 'billing_name')); 

否則,您可以Leftjoin的sales_flat_order_grid表與當前的集合。

+0

這很有效,謝謝! – AJ47

+0

太棒了:)。謝謝 – Ranipriyanka

相關問題