- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Magento 1.4 版,我向销售订单网格添加了额外的网格列(名称和 sku),返回的数据是正确的,但我在分页和记录总数方面遇到问题,我的代码如下:
首先我编辑了Mage_Adminhtml_Block_Sales_Order_Grid
:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ", ")'),
'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ", ")'),
)
);
$collection->getSelect()->group('entity_id');
$this->setCollection($collection);
return parent::_prepareCollection();
}
然后我重写此方法,以便在按名称或 sku 过滤时返回正确的结果
protected function _addColumnFilterToCollection($column)
{
if($this->getCollection() && $column->getFilter()->getValue())
{
if($column->getId() == 'skus'){
$this->getCollection()->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ", ")'),
)
)->getSelect()
->having('find_in_set(?, skus)', $column->getFilter()->getValue());
return $this;
}
if($column->getId() == 'names'){
$this->getCollection()->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ", ")'),
)
)->getSelect()
->having('find_in_set(?, names)', $column->getFilter()->getValue());
return $this;
}
}
return parent::_addColumnFilterToCollection($column);
}
然后我在Mage_Sales_Model_Mysql4_Order_Collection
类中编辑了这个方法getSelectCountSql()
:
public function getSelectCountSql()
{
$countSelect = parent::getSelectCountSql();
//added
$countSelect->reset(Zend_Db_Select::HAVING);
//end
$countSelect->resetJoinLeft();
return $countSelect;
}
如何计算行数?
最佳答案
也许有点晚了,但在你的代码中尝试使用 GROUP 代替 HAVING:
$countSelect->reset(Zend_Db_Select::GROUP);
因为您正在使用此声明:
$collection->getSelect()->group('entity_id');
关于添加名称和 Skus 列时,Magento 销售订单网格显示不正确的记录数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8764543/
我正在实现 Stripe 结账系统。 每次我尝试调用结帐 View 时,我都会遇到一个奇怪的 javascript 错误:IntegrationError:结帐的 SKU 需要 name 属性。 在仪
我正在使用 Magento 1.4 版,我向销售订单网格添加了额外的网格列(名称和 sku),返回的数据是正确的,但我在分页和记录总数方面遇到问题,我的代码如下: 首先我编辑了Mage_Adminht
目前,站点搜索将搜索标记为在搜索中可见的项目的所有 skus。这一切都很好。 当客户知道单个子项的 sku 时,就会出现问题。因此,假设产品有 20 英尺和 25 英尺两种版本。我们会将它们放入一个可
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 6 年前。 Improve
我如何使用 mysql 从 Magento 数据库中提取所有产品 ir、skus、产品名称(标题)和 desxription?我使用了以下查询并获得了除产品名称之外的所有属性。 SELECT e.en
我是一名优秀的程序员,十分优秀!