Geo*_*off 3 grid magento magento-1.5
我更改了app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php来自定义Orders网格上的内容.
在_getCollectionClass()我有这样的:
protected function _getCollectionClass()
{
//return 'sales/order_grid_collection';
return 'sales/order_collection';
}
Run Code Online (Sandbox Code Playgroud)
在_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();
}
Run Code Online (Sandbox Code Playgroud)
现在我已经改变了_prepareColumns()添加我必要的字段,所有的工作都很棒!除了一件事...
当我通过Billing或Shipping搜索订单时,出现错误.我已经将filter_index的('filter_index' => 'theindex')添加到所有必要的组件中,除了这两个字段Billing或Shipping之外,它们都工作得很好.
所以我也把filter_index放在那些上面.
一切都很棒.我可以搜索其他字段,但只要我搜索结算或发货字段,我就会收到此错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'billing_name' in 'where clause'
Run Code Online (Sandbox Code Playgroud)
我尝试过各种各样的东西但似乎没什么用.有人可以帮忙!???
当我退后一步然后开始查看数据库时,我突然意识到我想要的字段已经格式化了.我不需要连接/合并任何东西.我只是需要像其他人一样调用字段...
我的新_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();
}
Run Code Online (Sandbox Code Playgroud)
注意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',
));
Run Code Online (Sandbox Code Playgroud)
这就是她写的一切!
| 归档时间: |
|
| 查看次数: |
12121 次 |
| 最近记录: |