Description
Preconditions (*)
- Magento version: 2.3.3
- PHP version: 7.1.29; Apache version: 2.4.39; Mysql version: 5.7.26
Steps to reproduce (*)
- develop a plugin for block of product toolbar to sort product connection by sold quantity use joinleft method of Magento\Framework\DB\Select as below:
$toolbarCollection
->getSelect()
->joinLeft(
'sales_order',
'e.entity_id = sales_order.entity_id',
array('qty_ordered'=>'sales_order.total_qty_ordered'))
->group('e.entity_id')
->order('qty_ordered desc');
- flush the product page, the total number of connection items display only 1, not the true number, and don't get the right pagination.
Expected result (*)
- fix the bug and display the true number in amount.phtml;
- get the right pagination.
I try to fix it override the method of protected function _getSelectCountSql in file \Magento\Catalog\Model\ResourceModel\Product\Collection like below in a new module:
protected function _getSelectCountSql( ?\Magento\Framework\DB\Select $select = null , $resetLeftJoins = true )
{
$this -> _renderFilters();
$countSelect = $this -> _buildClearSelect( $select );
if ( count( $countSelect ->getPart( \Zend_Db_Select::GROUP ) ) > 0 ) {
$countSelect ->reset( \Zend_Db_Select::GROUP );
}
$countSelect -> columns( 'COUNT(DISTINCT e.entity_id)' );
if ( $resetLeftJoins ) {
$countSelect -> resetJoinLeft();
}
return $countSelect;
}
But it does not work.
Actual result (*)
- only get 1 item of product connection number;
- can't get the right total page number and display the real pagination.