Magento 2 Featured Products: How to Add Featured Products

For any online store to be successful, it is important that its customer experience should be as good as possible. Many factors are involved in this chain of experience and filter products experience in Magento 2 is one of them for the customers.

In such a situation, it is necessary that the store should be well designed, its design should be made according to the customers.

Filtering the products and showing them on the different pages like the Home page, category page, cms page, product details page increases the chances of sales.

Showing best seller products, featured products, New Products, special products is one of the most important aspects of Magento 2 eCommerce store that directly affects the customer shopping experience and sales growth.

 

Filter Products Extension in Magento 2

This extension will add functionality in your stores and allow admin users to decide filter attibute based on any type of attribute like best seller products attribute, featured products attribute, special products attribute using Wishusucess filter products extension of Magento 2.

  • Best Seller Products Filter
  • Featured Products Filter
  • New Products Filter
  • Special Products Filter

Magento 2 Filter Products

 

Read more: Magento 2 Return & Exchange (RMA) Extension: Send Mail

Admin Configuration of Filter Products Extension

In this Magento 2 extension given in admin configuration by which admin user can set title and description of filter attribute.

It gives your admin user the flexibility to customize everything in a better way.

Filter All Type of Products in Magento 2

 

Now, you have the options to filter the products by bestseller attribute, featured products attribute, special products attribute. If you need to change their title or need to add some message or description you can add their information from admin.

Store > Setting > Configuration > Wishusucess > Filterd Products

Products are filters based on the attributes, so as soon as you will enable the products as a featured or special or best seller that will display on the frontend.

This features allows you to enable or disable product attributes directly from the admin catalog product section.

 

How to Display Filter Products on Page

Choose the attribute that you want to filter products by in the catalog product section and get all products of that particular attribute by adding widget on the page.

Add Filter Attribute in Magento 2

Now, you simply need to keep enable to show the product in frontend and if you don't want to show then you can keep it disable. This Magento 2 Filter Product extension already has all this attribute in setup install data file. So you don't have to create all this product attributes.

Insert Filter Widget in Magento 2

You can add this widget of special products, featured products, best seller products, new products on any cms page or cms block like: home page, about us page etc.

Filter Featured Products in Magento 2

 

Magento 2 InstallData for Filter Attributes

Here, I am giving you the code to create filter products attributes to filter products programmatically. This code will create four cutom product attribute programmatically in Magento 2.

Wishusucess/FilterProducts/Setup/InstallData.php
<?php
namespace Wishusucess\FilterProducts\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
/**
* EAV setup factory
*
* @var EavSetupFactory
*/
private $eavSetupFactory;

/**
* Init
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory
->create(['setup' => $setup]);

/**
* Add attributes to the eav/attribute
*/
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'wishusucess_featured',
[
'group' => 'General',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Featured Product',
'input' => 'boolean',
'class' => '',
'source' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable'
],
'wishusucess_bestseller',
[
'group' => 'General',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Bestseller Product',
'input' => 'boolean',
'class' => '',
'source' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable'
],
'wishusucess_special',
[
'group' => 'General',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Special Product',
'input' => 'boolean',
'class' => '',
'source' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable'
],
'wishusucess_newproduct',
[
'group' => 'General',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'New Product',
'input' => 'boolean',
'class' => '',
'source' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable'
]
);
}
}

Just create a simple registration.php file and module.xml file to create the extension in Magento 2 and then create a folder inside of your module name with Setup and then create InstallData.php file and paste above code.

Now run the upgrade command in order to create the all custom product attribute programmatically in Magento 2.

 

That's all!

If you need help to implement this full extension you can directly contact me.

I am here to help you 24*7

Magento 2 Free Help and Support

Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

 

Recommended Posts:

Form Field Manager: How to Manage Magento 2 Customer Form Fields

RMA Extension Magento 2: What is RMA and How it Works

Google reCAPTCHA in Magento 2: How to Add reCaptcha