I want to override Magento\Catalog\Model\ResourceModel\Product\Collection
using preference to modify the _buildClearSelect($select = null)
method.
For this, I have created di.xml
with the following code:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Model\ResourceModel\Product\Collection" type="Vendor\ModuleName\Model\ResourceModel\Product\Collection" />
</config>
and Collection.php
namespace Vendor\ModuleName\Model\ResourceModel\Product;
class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
{
/**
* Build clear select
*
* @param \Magento\Framework\DB\Select $select
* @return \Magento\Framework\DB\Select
*/
protected function _buildClearSelect($select = null)
{
$select = parent::_buildClearSelect($select);
$select->reset(\Magento\Framework\DB\Select::GROUP);
return $select;
}
}
Above code is not working. I have already tried to flush cache and remove the code directory from the generated directory.
Any help would be appreciated!