5

Why does my ListProduct classnot overriding, I have overridden the Magento/Catalogs Controller and other Blocks...seems like a problem in only this Block class.

Where can the possible issue be?

Cleared var/gen, cache

If i intentionally make error in tis class, it throws up, but only getProductCollection() not overriding

\Vendor\Catalog\etc\di.xml

<?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\Controller\Category\View" type="Vendor\Catalog\Controller\Category\View" />
    <preference for="Magento\Catalog\Block\Product\ListProduct" type="Vendor\Catalog\Block\Product\ListProduct" />
    <preference for="Magento\Catalog\Block\Product\ProductList\Toolbar" type="Vendor\Catalog\Block\Product\ProductList\Toolbar" />
  </config>

\Vendor\Catalog\etc\module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Vendor_Catalog" setup_version="2.2.0">
    <sequence>
        <module name="Magento_Catalog"/>
        <module name="Magento_CatalogSearch"/>
        <module name="Magento_Swatches"/>
        <module name="Magento_ConfigurableProduct"/>
        <module name="Magento_Eav"/>
        <module name="Magento_Customer"/>
        <module name="Magento_Store"/>
        <module name="Magento_Backend"/>
        <module name="Magento_MediaStorage"/>
        <module name="Magento_Config"/>
        <module name="Magento_LayeredNavigation"/>
        <module name="Magento_Theme"/>
     </sequence>
</module>

\Vendor\Catalog\Block\Product\ListProduct.php

<?php
namespace Vendor\Catalog\Block\Product;

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\Entity\Collection\AbstractCollection;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\DataObject\IdentityInterface;

class ListProduct extends \Magento\Catalog\Block\Product\ListProduct
{

  protected $tglssearchHelper;
/**
 * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
 */
protected $catalogResourceModelProductCollectionFactory;

/**
 * @var \Magento\Catalog\Model\Config
 */
protected $catalogConfig;


protected $storeManager;
protected $_defaultToolbarBlock = 'Magento\Catalog\Block\Product\ProductList\Toolbar';

public function __construct(
    /*passing all Constructors parameters to the parent class */
    \Magento\Catalog\Block\Product\Context $context,
    \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
    \Magento\Catalog\Model\Layer\Resolver $layerResolver,
     CategoryRepositoryInterface $categoryRepository,
    \Magento\Framework\Url\Helper\Data $urlHelper,
    /*passing all Constructors parameters to the parent class */

    \Vendor\CatalogSearch\Helper\Data $tglssearchHelper,
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $catalogResourceModelProductCollectionFactory,
    \Magento\Catalog\Model\Config $catalogConfig,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    array $data = []
    ) {
    $this->tglssearchHelper = $tglssearchHelper;
    $this->catalogResourceModelProductCollectionFactory = $catalogResourceModelProductCollectionFactory;
    $this->catalogConfig = $catalogConfig;
    $this->storeManager = $storeManager;

      parent::__construct(
        $context,
        $postDataHelper,
        $layerResolver,
        $categoryRepository,
        $urlHelper,
        $data
    );
    //$this->tglssearchHelper = $tglssearchHelper;
}

//Overriden custom method not getting called on Click of filterable attributes in search page

protected function _getProductCollection()
{
   echo 'my product collection';
    ... Here core method's getProductCollection() is calling...
}
  • 2
    hi you got any solution for this..? – Rahul Apr 27 '17 at 7:23
  • Hi, I've got same problem here, any solutions? Thanks – lpFranz Aug 23 '18 at 14:31

Your Answer

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

Browse other questions tagged or ask your own question.