gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:07:32 25 4
gpt4 key购买 nike

我更改了 app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php 以自定义Orders 网格上的内容。 p>

_getCollectionClass() 我有这个:

protected function _getCollectionClass()
{
//return 'sales/order_grid_collection';
return 'sales/order_collection';
}

_prepareCollection() 我有这个:

protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());

$collection->getSelect()->joinLeft(array('s1' => 'sales_flat_order_address'),'main_table.shipping_address_id = s1.entity_id',array('region','firstname','lastname'));
$collection->getSelect()->joinLeft(array('s2'=>'sales_flat_order_address'),'main_table.billing_address_id = s2.entity_id',array('firstname','lastname'));

$collection->getSelect()->columns(new Zend_Db_Expr("CONCAT(s2.firstname, ' ',s2.lastname) AS billing_name"));
$collection->getSelect()->columns(new Zend_Db_Expr("CONCAT(s1.firstname, ' ',s1.lastname) AS shipping_name"));

$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight','sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status','sfo.base_grand_total','sfo.grand_total')); // New
$collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street','sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone')); // New


$this->setCollection($collection);

return parent::_prepareCollection();
}

现在我更改了 _prepareColumns() 以添加我的必要字段并且一切正常!除了一件事......

当我按BillingShipping 搜索订单时,出现错误。我已将 filter_index('filter_index' => 'theindex')添加到所有必要的组件中,它们都很好用,除了这两个字段 Billing运输

所以我也把 filter_index 放在那些上面。

一切顺利。我可以搜索其他字段,但是当我搜索 BillingShipping 字段时,我收到此错误:

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

我尝试了各种方法,但似乎没有任何效果。有人可以帮忙吗!???


最佳答案

当我退后一步并开始查看数据库时,我突然意识到我想要的字段已经格式化。我不需要连接/合并任何东西。我只需要像调用其他字段一样调用这些字段...

我的新 _prepareCollection() 函数是:

protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());

$collection->getSelect()->joinLeft(array('sfog' => 'sales_flat_order_grid'),'main_table.entity_id = sfog.entity_id',array('sfog.shipping_name','sfog.billing_name'));

$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight','sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status','sfo.base_grand_total','sfo.grand_total')); // New
$collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street','sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone')); // New


$this->setCollection($collection);

return parent::_prepareCollection();
}

注意 sfog 数组。

这将进入数据库的 sales_flat_order_grid 表,并获取原始网格中的预格式化名称。 我想知道这是否与从该表调用原始网格这一事实有关(讽刺)- :P

然后,就像确保在两个名称字段中执行 filter_index(就像所有其他字段一样)

例子:

$this->addColumn('billing_name', array(
'header' => Mage::helper('sales')->__('Bill to Name'),
'index' => 'billing_name',
'filter_index' => 'sfog.billing_name',
));

这就是她写的全部!

关于grid - Magento - SQLSTATE [42S22] : Column not found: 1054 Unknown column 'billing_name' in 'where clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9027741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com