Magento:SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'billing_name'

时间:2017-06-30 15:12:47

标签: php magento magento-1.8

尝试过滤管理网格以查看特定产品的销售历史记录,但在尝试按结算名称过滤时收到以下错误:

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();
}

该列会正确返回包含产品的订单中的所有帐单名称,我无法按名称过滤列。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

magento sales_flat_order和sales_flat_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'));  

否则,您可以使用当前集合将sales_flat_order_grid表左键连接。