How to show custom collection as the normal product listing?

Created by Rosa Truong, Modified on Mon, 23 Dec, 2019 at 9:44 AM by Rosa Truong


I want to show my custom collection( means only showing products whose manufacture is "Dell") as the normal product listing in this module:  

Can you please let me know how to achieve that? 


Regarding your query, we have checked and would like to give you the guide to filter attribute product.
In your case, the attribute manufacture is "Dell"
Please follow these steps:

Step 1: Go to the admin to inspect attribute manufacture and get value filter 

Step 2: Edit this file app/code/Bss/HelloWorld/Block/Index/Collection.php

namespace Bss\HelloWorld\Block\Index;
use Magento\Catalog\Block\Product\ListProduct;
use Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection;
use Magento\Catalog\Model\ResourceModel\Product\Collection as Collections;
use Magento\Catalog\Block\Product\ProductList\Toolbar;
class Collection extends ListProduct {

    public function setProductCollection(AbstractCollection $collection)
        $this->_productCollection = $collection;

    public function getLoadedProductCollection()
        return $this->_productCollection;

    protected function _getProductCollection()
        if ($this->_productCollection === null) { 
            $this->_productCollection = $this->initializeProductCollection();

        return $this->_productCollection;

    private function addToolbarBlock(Collections $collection)
        $toolbarLayout = $this->getToolbarFromLayout();

        if ($toolbarLayout) {
            $this->configureToolbar($toolbarLayout, $collection);

    private function getToolbarFromLayout()
        $blockName = $this->getToolbarBlockName();

        $toolbarLayout = false;

        if ($blockName) {
            $toolbarLayout = $this->getLayout()->getBlock($blockName);

        return $toolbarLayout;

    private function configureToolbar(Toolbar $toolbar, Collections $collection)
        // use sortable parameters
        $orders = $this->getAvailableOrders();
        if ($orders) {
        $sort = $this->getSortBy();
        if ($sort) {
        $dir = $this->getDefaultDirection();
        if ($dir) {
        $modes = $this->getModes();
        if ($modes) {
        // set collection to toolbar and apply sort
        $this->setChild('toolbar', $toolbar);

    private function initializeProductCollection()
        $layer = $this->getLayer();
        /* @var $layer Layer */
        if ($this->getShowRootCategory()) {

        // if this is a product view page
        if ($this->_coreRegistry->registry('product')) {
            // get collection of categories this product is associated with
            $categories = $this->_coreRegistry->registry('product')
                ->getCategoryCollection()->setPage(1, 1)
            // if the product is associated with any category
            if ($categories->count()) {
                // show products from this category

        $origCategory = null;
        if ($this->getCategoryId()) {
            try {
                $category = $this->categoryRepository->get($this->getCategoryId());
            } catch (NoSuchEntityException $e) {
                $category = null;

            if ($category) {
                $origCategory = $layer->getCurrentCategory();
        $collection = $layer->getProductCollection();


        if ($origCategory) {


            ['collection' => $collection]

        return $collection;


Note: Check and edit this code with the corresponding value on your site


Step 3: Flush the cache and check the result  

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article