How to Get Featured Product Collection

Create Featured Products block

Directory

app/code/VendorName/ModuleName/Block/FeaturedProducts.php

Content for this file

<?php

namespace VendorName\ModuleName\Block;

class FeaturedProducts extends AbstractSlider
{
    /**
     * get collection of feature products
     * @return mixed
     */
    public function getProductCollection()
    {
        $visibleProducts = $this->_catalogProductVisibility->getVisibleInCatalogIds();
        $collection = $this->_productCollectionFactory->create()->setVisibility($visibleProducts);
        $collection->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addAttributeToSelect('*')
            ->addStoreFilter($this->getStoreId())
            ->setPageSize($this->getProductsCount())
            ->addAttributeToFilter('is_featured', '1');
        return $collection;
    }
}

Insert in phtml file

Directory

VendorName/ModuleName/view/frontend/templates/list.phtml

Content for this file

<?php
$collection = $block->getProductCollection();
foreach ($collection as $_product) {
    echo $product->getName() . ' - ' . $product->getProductUrl() . '<br />';
}

Flush the Cache and test the result.

 

If you are looking for Magento Developer, visit Magento Development Agency.