15/08/2022
We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
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;
}
}
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.