1

I need a page where all products should be displayed. All products from all categories, also including filters by attributes.

I have tried to use the following block

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}

However, it doesn't work.

When I create a parent category I get nested categories and they are displayed under the All categories category, this is not what I need.

Please suggest a way to display all products on a single page.

0

Add following line in your cms page.

{{block class="Vendor\Module\Block\ListProduct" name="custom.product.list" template="Vendor_Module::product/list.phtml"}}

Create your custom block and phtml file as given below.

Vendor/Module/Block/ListProduct.php

<?php
...
...

private $productCollection;

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollection
) {
    $this->productCollection = $productCollection;
    parent::__construct($context);
}

public function getProductCollection()
{
    return $this->productCollection->create();
}

Vendor/Module/view/frontend/templates/product/list.phtml

$collection = $block->getProductCollection();

foreach ($collection as $product) {
    print_r($product->getId());
}

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.