cancel
Showing results for 
Search instead for 
Did you mean: 

Incompatible Argument Type Required: Collection Factory

SOLVED

Incompatible Argument Type Required: Collection Factory

Hi,

I've created a custom module to extend my theme module for certain functionality, while overriding the particular class in theme module, Facing compilation error while running set:di:compile. Can anyone please share me the steps to resolve this error?

Theme folder code

    /**
     * @param \Magento\Catalog\Block\Product\Context $context
     * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
     * @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
     * @param \Magento\Framework\App\Http\Context $httpContext
     * @param \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder
     * @param \Emthemes\FilterProduct\Model\Rule $rule
     * @param \Magento\Widget\Helper\Conditions $conditionsHelper
     * @param array $data
     */
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Emthemes\FilterProduct\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
        \Emthemes\FilterProduct\Model\ResourceModel\Bestsellers\CollectionFactory $bestSellerCollectionFactory,
        \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
        \Emthemes\FilterProduct\Model\Rule $rule,
        \Magento\Widget\Helper\Conditions $conditionsHelper,
        \Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
        \Magento\Framework\Url\Helper\Data $urlHelper,
        \Magento\Review\Model\ReviewFactory $reviewFactory,
        \Emthemes\FilterProduct\Block\ImageBuilderFactory $customImageBuilderFactory,
        array $data = []
    ) {
        $this->productCollectionFactory = $productCollectionFactory;
        $this->bestSellerCollectionFactory = $bestSellerCollectionFactory;
        $this->catalogProductVisibility = $catalogProductVisibility;
        $this->httpContext = $httpContext;
        $this->sqlBuilder = $sqlBuilder;
        $this->rule = $rule;
        $this->urlHelper = $urlHelper;
        $this->conditionsHelper = $conditionsHelper;
        $this->imageHelperFactory = $imageHelperFactory;
        
        $this->reviewFactory = $reviewFactory;
        $this->customImageBuilderFactory = $customImageBuilderFactory;
        parent::__construct(
            $context,
            $data
        );
    }

My custom Module code

 /**
     * @param \Magento\Catalog\Block\Product\Context $context
     * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
     * @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
     * @param \Magento\Framework\App\Http\Context $httpContext
     * @param \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder
     * @param \Emthemes\FilterProduct\Model\Rule $rule
     * @param \Magento\Widget\Helper\Conditions $conditionsHelper
     * @param array $data
     */
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Emthemes\FilterProduct\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
        \Emthemes\FilterProduct\Model\ResourceModel\Bestsellers\CollectionFactory $bestSellerCollectionFactory,
        \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
        \Emthemes\FilterProduct\Model\Rule $rule,
        \Magento\Widget\Helper\Conditions $conditionsHelper,
        \Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
        \Magento\Framework\Url\Helper\Data $urlHelper,
        \Magento\Review\Model\ReviewFactory $reviewFactory,
        \Emthemes\FilterProduct\Block\ImageBuilderFactory $customImageBuilderFactory,
        \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        array $data = [])
    {
        $this->productCollectionFactory = $productCollectionFactory;
        $this->bestSellerCollectionFactory = $bestSellerCollectionFactory;
        $this->catalogProductVisibility = $catalogProductVisibility;
        $this->httpContext = $httpContext;
        $this->sqlBuilder = $sqlBuilder;
        $this->rule = $rule;
        $this->urlHelper = $urlHelper;
        $this->conditionsHelper = $conditionsHelper;
        $this->imageHelperFactory = $imageHelperFactory;
        $this->_categoryFactory = $categoryFactory;
        $this->_storeManager = $storeManager;
        parent::__construct(
            $context,
            $data
        );
    }

Error Im facing is given below:

Errors during compilation:
WebMDT\Emtheme\Product\ProductsList
Incompatible argument type: Required type: \Emthemes\FilterProduct\Model\ResourceModel\Product\CollectionFactory. Actual type: array; File:
/var/www/html/SITE-KixNStix/app/code/WebMDT/Emtheme/Product/ProductsList.php

Total Errors Count: 1

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Incompatible Argument Type Required: Collection Factory

@rbalamuruga 
If you are overriding any file and also extending it then you must return same__construct parameters of parent file from your overridden file.

Please update your __construct code with below:

public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Emthemes\FilterProduct\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
        \Emthemes\FilterProduct\Model\ResourceModel\Bestsellers\CollectionFactory $bestSellerCollectionFactory,
        \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
        \Emthemes\FilterProduct\Model\Rule $rule,
        \Magento\Widget\Helper\Conditions $conditionsHelper,
        \Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
        \Magento\Framework\Url\Helper\Data $urlHelper,
        \Magento\Review\Model\ReviewFactory $reviewFactory,
        \Emthemes\FilterProduct\Block\ImageBuilderFactory $customImageBuilderFactory,
        \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        array $data = [])
    {
        $this->productCollectionFactory = $productCollectionFactory;
        $this->bestSellerCollectionFactory = $bestSellerCollectionFactory;
        $this->catalogProductVisibility = $catalogProductVisibility;
        $this->httpContext = $httpContext;
        $this->sqlBuilder = $sqlBuilder;
        $this->rule = $rule;
        $this->urlHelper = $urlHelper;
        $this->conditionsHelper = $conditionsHelper;
        $this->imageHelperFactory = $imageHelperFactory;
        $this->_categoryFactory = $categoryFactory;
        $this->_storeManager = $storeManager;
        parent::__construct(
            $context,
            $productCollectionFactory,
            $bestSellerCollectionFactory,
            $catalogProductVisibility,
            $httpContext,
            $sqlBuilder,
            $rule,
            $conditionsHelper,
            $imageHelperFactory,
            $urlHelper,
            $reviewFactory,
            $customImageBuilderFactory,
            $data
        );
    }

  If issue is solved,Click Kudos & Accept as Solution

View solution in original post

5 REPLIES 5

Re: Incompatible Argument Type Required: Collection Factory

@rbalamuruga 
If you are overriding any file and also extending it then you must return same__construct parameters of parent file from your overridden file.

Please update your __construct code with below:

public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Emthemes\FilterProduct\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
        \Emthemes\FilterProduct\Model\ResourceModel\Bestsellers\CollectionFactory $bestSellerCollectionFactory,
        \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
        \Emthemes\FilterProduct\Model\Rule $rule,
        \Magento\Widget\Helper\Conditions $conditionsHelper,
        \Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
        \Magento\Framework\Url\Helper\Data $urlHelper,
        \Magento\Review\Model\ReviewFactory $reviewFactory,
        \Emthemes\FilterProduct\Block\ImageBuilderFactory $customImageBuilderFactory,
        \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        array $data = [])
    {
        $this->productCollectionFactory = $productCollectionFactory;
        $this->bestSellerCollectionFactory = $bestSellerCollectionFactory;
        $this->catalogProductVisibility = $catalogProductVisibility;
        $this->httpContext = $httpContext;
        $this->sqlBuilder = $sqlBuilder;
        $this->rule = $rule;
        $this->urlHelper = $urlHelper;
        $this->conditionsHelper = $conditionsHelper;
        $this->imageHelperFactory = $imageHelperFactory;
        $this->_categoryFactory = $categoryFactory;
        $this->_storeManager = $storeManager;
        parent::__construct(
            $context,
            $productCollectionFactory,
            $bestSellerCollectionFactory,
            $catalogProductVisibility,
            $httpContext,
            $sqlBuilder,
            $rule,
            $conditionsHelper,
            $imageHelperFactory,
            $urlHelper,
            $reviewFactory,
            $customImageBuilderFactory,
            $data
        );
    }

  If issue is solved,Click Kudos & Accept as Solution

Re: Incompatible Argument Type Required: Collection Factory

Hello @verma_mallika 

Thanks for addressing my Issue I'm having another doubt that I've extending as you said, but I'm getting another error is it cannot getting the template file.

Source code for theme file:

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

namespace Emthemes\FilterProduct\Block\Product;
/**
 * Catalog Products List widget block
 * Class ProductsList
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class ProductsList extends \Magento\Catalog\Block\Product\AbstractProduct implements \Magento\Widget\Block\BlockInterface
{
    /**
     * Default value for products count that will be shown
     */
    const DEFAULT_PRODUCTS_COUNT = 10;

    /**
     * Name of request parameter for page number value
     */
    const PAGE_VAR_NAME = 'np';

    /**
     * Default value for products per page
     */
    const DEFAULT_PRODUCTS_PER_PAGE = 5;

    /**
     * Default value whether show pager or not
     */
    const DEFAULT_SHOW_PAGER = false;

    /**
     * Instance of pager block
     *
     * @var \Magento\Catalog\Block\Product\Widget\Html\Pager
     */
    protected $pager;

    /**
     * @var \Magento\Framework\App\Http\Context
     */
    protected $httpContext;

    /**
     * Catalog product visibility
     *
     * @var \Magento\Catalog\Model\Product\Visibility
     */
    protected $catalogProductVisibility;

    /**
     * Product collection factory
     *
     * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
     */
    protected $urlHelper;
    protected $productCollectionFactory;
    protected $bestSellerCollectionFactory;

    /**
     * @var \Magento\Rule\Model\Condition\Sql\Builder
     */
    protected $sqlBuilder;

    /**
     * @var \Emthemes\FilterProduct\Model\Rule
     */
    protected $rule;

    /**
     * @var \Magento\Widget\Helper\Conditions
     */
    protected $conditionsHelper;
    
    protected $imageHelperFactory;

    /**
     * @param \Magento\Catalog\Block\Product\Context $context
     * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
     * @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
     * @param \Magento\Framework\App\Http\Context $httpContext
     * @param \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder
     * @param \Emthemes\FilterProduct\Model\Rule $rule
     * @param \Magento\Widget\Helper\Conditions $conditionsHelper
     * @param array $data
     */
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Emthemes\FilterProduct\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
        \Emthemes\FilterProduct\Model\ResourceModel\Bestsellers\CollectionFactory $bestSellerCollectionFactory,
        \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
        \Emthemes\FilterProduct\Model\Rule $rule,
        \Magento\Widget\Helper\Conditions $conditionsHelper,
        \Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
        \Magento\Framework\Url\Helper\Data $urlHelper,
        \Magento\Review\Model\ReviewFactory $reviewFactory,
        \Emthemes\FilterProduct\Block\ImageBuilderFactory $customImageBuilderFactory,
        array $data = []
    ) {
        $this->productCollectionFactory = $productCollectionFactory;
        $this->bestSellerCollectionFactory = $bestSellerCollectionFactory;
        $this->catalogProductVisibility = $catalogProductVisibility;
        $this->httpContext = $httpContext;
        $this->sqlBuilder = $sqlBuilder;
        $this->rule = $rule;
        $this->urlHelper = $urlHelper;
        $this->conditionsHelper = $conditionsHelper;
        $this->imageHelperFactory = $imageHelperFactory;
        
        $this->reviewFactory = $reviewFactory;
        $this->customImageBuilderFactory = $customImageBuilderFactory;
        parent::__construct(
            $context,
            $data
        );
    }

    /**
     * {@inheritdoc}
     */
    protected function _construct()
    {
        parent::_construct();
        $this->addColumnCountLayoutDepend('empty', 6)
            ->addColumnCountLayoutDepend('1column', 5)
            ->addColumnCountLayoutDepend('2columns-left', 4)
            ->addColumnCountLayoutDepend('2columns-right', 4)
            ->addColumnCountLayoutDepend('3columns', 3);

        $this->addData([
            'details_renderer_list_name' => 'emthemes.filterproduct.product.type.details.renderers',
            'cache_lifetime' => 86400,
            'cache_tags' => [\Magento\Catalog\Model\Product::CACHE_TAG,
        ], ]);
    }

    /**
     * Get key pieces for caching block content
     *
     * @return array
     */
    public function getCacheKeyInfo()
    {
        $conditions = $this->getData('conditions')
            ? $this->getData('conditions')
            : $this->getData('conditions_encoded');
		$conditions = json_encode($this->getData());
        return [
            'CATALOG_PRODUCTS_LIST_WIDGET',
            $this->_storeManager->getStore()->getId(),
            $this->_design->getDesignTheme()->getId(),
            $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP),
            intval($this->getRequest()->getParam(self::PAGE_VAR_NAME, 1)),
            $this->getProductsPerPage(),
            $conditions
        ];
    }

    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.NPathComplexity)
     */
    public function getProductPriceHtml(
        \Magento\Catalog\Model\Product $product,
        $priceType = null,
        $renderZone = \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
        array $arguments = []
    ) {
        if (!isset($arguments['zone'])) {
            $arguments['zone'] = $renderZone;
        }
        $arguments['price_id'] = isset($arguments['price_id'])
            ? $arguments['price_id']
            : 'old-price-' . $product->getId() . '-' . $priceType;
        $arguments['include_container'] = isset($arguments['include_container'])
            ? $arguments['include_container']
            : true;
        $arguments['display_minimal_price'] = isset($arguments['display_minimal_price'])
            ? $arguments['display_minimal_price']
            : true;

            /** @var \Magento\Framework\Pricing\Render $priceRender */
        $priceRender = $this->getLayout()->getBlock('product.price.render.default');

        $price = '';
        if ($priceRender) {
            $price = $priceRender->render(
                \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
                $product,
                $arguments
            );
        }
        return $price;
    }

    /**
     * {@inheritdoc}
     */
    protected function _beforeToHtml()
    {
        $this->setProductCollection($this->createCollection());
        return parent::_beforeToHtml();
    }
    
    public function getAddToCartPostParams(\Magento\Catalog\Model\Product $product)
    {
        $url = $this->getAddToCartUrl($product);
        return [
            'action' => $url,
            'data' => [
                'product' => $product->getEntityId(),
                \Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED =>
                    $this->urlHelper->getEncodedUrl($url),
            ]
        ];
    }
    
    protected function _getBestSellerProductCollection()
    {
        $collection = $this->bestSellerCollectionFactory->create();
        $table = $collection->getTable('sales_bestsellers_aggregated_daily');
        $collection->getSelect()->join(array('r' => $table), 'r.product_id=e.entity_id', array('*'))->group('e.entity_id');
        //$collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());

        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()
            ->setPageSize($this->getPageSize())
            ->setCurPage($this->getRequest()->getParam(self::PAGE_VAR_NAME, 1));

        $conditions = $this->getConditions();
        $conditions->collectValidatedAttributes($collection);
        $this->sqlBuilder->attachConditionToCollection($collection, $conditions);

        return $collection;
    }
    
    protected function _getAllProductProductCollection()
    {
        /** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
        $collection = $this->productCollectionFactory->create();
        $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());

        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()
            ->setPageSize($this->getPageSize())
            ->setCurPage($this->getRequest()->getParam(self::PAGE_VAR_NAME, 1));

        $conditions = $this->getConditions();
        $conditions->collectValidatedAttributes($collection);
        $this->sqlBuilder->attachConditionToCollection($collection, $conditions);

        return $collection;
    }

    public function createCollection()
    {
        $displayType = $this->getDisplayType();
        $collection = null;
        switch($displayType)
        {
            case 'all_products': $collection = $this->_getAllProductProductCollection();break;
            case 'bestseller_products': $collection = $this->_getBestSellerProductCollection();break;
        }
        $sort = explode(' ', $this->getData('order_by'));
        $collection->addAttributeToSort($sort[0],$sort[1]);
        $this->reviewFactory->create()->appendSummary($collection);
        return $collection;
    }

    protected function getConditions()
    {
        $conditions = $this->getData('conditions_encoded')
            ? $this->getData('conditions_encoded')
            : $this->getData('conditions');

        if ($conditions) {
            $conditions = $this->conditionsHelper->decode($conditions);
        }

        $this->rule->loadPost(['conditions' => $conditions]);
        return $this->rule->getConditions();
    }
public function getProductsCount() { if ($this->hasData('products_count')) { return $this->getData('products_count'); } if (null === $this->getData('products_count')) { $this->setData('products_count', self::DEFAULT_PRODUCTS_COUNT); } return $this->getData('products_count'); } public function getProductsPerPage() { if (!$this->hasData('products_per_page')) { $this->setData('products_per_page', self::DEFAULT_PRODUCTS_PER_PAGE); } return $this->getData('products_per_page'); } public function showPager() { if (!$this->hasData('show_pager')) { $this->setData('show_pager', self::DEFAULT_SHOW_PAGER); } return (bool)$this->getData('show_pager'); } /** * Retrieve how many products should be displayed on page * * @return int */ protected function getPageSize() { return $this->showPager() ? $this->getProductsPerPage() : $this->getProductsCount(); } /** * Render pagination HTML * * @return string */ public function getPagerHtml() { if ($this->showPager() && $this->getProductCollection()->getSize() > $this->getProductsPerPage()) { if (!$this->pager) { $this->pager = $this->getLayout()->createBlock( 'Magento\Catalog\Block\Product\Widget\Html\Pager', 'widget.products.list.pager' ); $this->pager->setUseContainer(true) ->setShowAmounts(true) ->setShowPerPage(false) ->setPageVarName(self::PAGE_VAR_NAME) ->setLimit($this->getProductsPerPage()) ->setTotalLimit($this->getProductsCount()) ->setCollection($this->getProductCollection()); } if ($this->pager instanceof \Magento\Framework\View\Element\AbstractBlock) { return $this->pager->toHtml(); } } return ''; } /** * Return identifiers for produced content * * @return array */ public function getIdentities() { return [\Magento\Catalog\Model\Product::CACHE_TAG]; } /** * Get value of widgets' title parameter * * @return mixed|string */ public function getTitle() { return $this->getData('title'); } public function getTemplate() { $template = $this->getData('filter_template'); if($template == 'custom') { return $this->getData('custom_template'); } else { return $template; } } public function isShow($item) { /*$show = $this->getData('show'); if (strpos($show,$item) !== false) { return true; }else{ return false; }*/ return (($this->getData('show') != '') && in_array($item, explode(',', $this-> getData('show')))); } public function getImage($product, $imageId, $attributes = []) { $width = $this->getData('thumb_width'); $height = $this->getData('thumb_height'); $attributes = array('width'=>$width,'height'=>$height); $imageBuilder = $this->customImageBuilderFactory->create(); return $imageBuilder->setProduct($product) ->setImageId($imageId) ->setAttributes($attributes) ->create(); return $html; } }

and here is my custom module code

 

 

<?php

namespace WebMDT\Emtheme\Product;

class ProductsList extends \Emthemes\FilterProduct\Block\Product\ProductsList{

    protected $_categoryFactory;

    protected $_storeManager;

    protected $cat;

    /**
     * @param \Magento\Catalog\Block\Product\Context $context
     * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
     * @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
     * @param \Magento\Framework\App\Http\Context $httpContext
     * @param \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder
     * @param \Emthemes\FilterProduct\Model\Rule $rule
     * @param \Magento\Widget\Helper\Conditions $conditionsHelper
     * @param array $data
     */
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Emthemes\FilterProduct\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
        \Emthemes\FilterProduct\Model\ResourceModel\Bestsellers\CollectionFactory $bestSellerCollectionFactory,
        \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
        \Emthemes\FilterProduct\Model\Rule $rule,
        \Magento\Widget\Helper\Conditions $conditionsHelper,
        \Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
        \Magento\Framework\Url\Helper\Data $urlHelper,
        \Magento\Review\Model\ReviewFactory $reviewFactory,
        \Emthemes\FilterProduct\Block\ImageBuilderFactory $customImageBuilderFactory,
        \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryFactory,
        \Magento\Catalog\Model\Category $cat,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        array $data = [])
    {
        $this->productCollectionFactory = $productCollectionFactory;
        $this->bestSellerCollectionFactory = $bestSellerCollectionFactory;
        $this->catalogProductVisibility = $catalogProductVisibility;
        $this->httpContext = $httpContext;
        $this->sqlBuilder = $sqlBuilder;
        $this->rule = $rule;
        $this->urlHelper = $urlHelper;
        $this->conditionsHelper = $conditionsHelper;
        $this->imageHelperFactory = $imageHelperFactory;
        $this->_categoryFactory = $categoryFactory;
        $this->cat = $cat;
        $this->_storeManager = $storeManager;
        parent::__construct(
            $context,
            $productCollectionFactory,
            $bestSellerCollectionFactory,
            $catalogProductVisibility,
            $httpContext,
            $sqlBuilder,
            $rule,
            $conditionsHelper,
            $imageHelperFactory,
            $urlHelper,
            $reviewFactory,
            $customImageBuilderFactory,
            $data
        );
    }

    public function getProductCollection()
    {
        $categoryName = $this->getData('category_name');
        $category = $this->_categoryFactory->create()->addAttributeToFilter('name',$categoryName)->addIsActiveFilter()->setPageSize(1);
        $storeId = $this->_storeManager->getStore()->getId();
        $categorySet = $this->_storeManager->getStore($storeId)->getRootCategoryId();
        if($category->getSize()){
                $categorySet = $this->cat->load($category->getFirstItem()->getId());
        }
        $collection = $this->productCollectionFactory->create();
        $collection->addAttributeToSelect('*');
        $collection->addCategoryFilter($categorySet);
        $collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
        $collection->addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
        return $collection;
    }

    /**
     * Prepare and return product collection
     *
     * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
     */
    public function createCollection()
    {
        $displayType = $this->getDisplayType();
        $collection = null;
        switch($displayType)
        {
            case 'all_products': $collection = $this->_getAllProductProductCollection();break;
            case 'bestseller_products': $collection = $this->_getBestSellerProductCollection();break;
            case 'category_filter': $collection = $this->getProductCollection();break;
        }
        $sort = explode(' ', $this->getData('order_by'));
        $collection->addAttributeToSort($sort[0],$sort[1]);
        $this->reviewFactory->create()->appendSummary($collection);
        return $collection;
    }
}

Error which i got is Invalid template file in module product\products_list1

 

 

While calling widget in block file my code seems to be like this in wysiwyg editor.

{{widget type="Emthemes\FilterProduct\Block\Product\ProductsList" display_type="all_products" products_count="8" order_by="name ASC" show="thumb,name,review,price,addtocart,addto" thumb_width="320" thumb_height="320" filter_template="custom" custom_template="grid_noslider.phtml"}}

Please help me to resolve this issue.

Re: Incompatible Argument Type Required: Collection Factory

@rbalamuruga 

You need to create that phtml file in your module on same path in view directory.

Re: Incompatible Argument Type Required: Collection Factory

 

@rbalamuruga 
You can also try below methods if you don't want to create file in your module.

 

namespace WebMDT\Emtheme\Product;

class ProductsList extends \Emthemes\FilterProduct\Block\Product\ProductsList{
protected $_template = 'Emthemes_FilterProduct::template path';
}

OR

public function __construct(<args>)
{
    ...
  $this->setTemplate('Emthemes_FilterProduct::template path');
    ...
}

If issue is solved,Click Kudos & Accept as Solution

 

Re: Incompatible Argument Type Required: Collection Factory

I've made a custom module to expand my subject module for specific usefulness, while superseding the specific class in topic module, Confronting gathering mistake while running set:di:compile. Might anybody at any point kindly share me the moves toward resolve this blunder?

https://www.eleganceblog.com/classy-winter-nails-colors-ideas/