0

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!

  • kindly use public function __construct() function and let me know if any issue – mohith Sep 20 '19 at 9:44
  • Hi @mohith! I have tried this but no success. – Sanchit Gupta Sep 20 '19 at 9:54
0

Add dependency to your etc/module.xml

        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>

and clear cache and generated/code/

Happy coding

  • 1
    Hi lazy_coder! it is already implemented. – Sanchit Gupta Sep 20 '19 at 9:49
0

Add dependency to your etc/module.xml

   <sequence>
        <module name="Magento_Backend" />
    </sequence>
  • Hello Mohith! Can you please explain why we add Magento_Backend? – Sanchit Gupta Sep 20 '19 at 10:44
  • Its working right!!! – mohith Sep 20 '19 at 10:47
  • No, it's not working. – Sanchit Gupta Sep 20 '19 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.