Add Multiple Product Attribute Using InstallData in Magento2

In this article, I am going to explain how to add multiple product attribute or create product attributes by using the installData.php file programmatically in Magento 2.

Magento 2  eCommerce follows the EAV database model, So in such a situation, it becomes necessary that its standard should be followed. So in order to add the custom attributes in Magento 2, we have to create the InsatllData PHP file.

In the chances of any online e-commerce website being successful, it matters a lot that how well you define the product.

When we want to define the product in a better way, we take the help of custom attribute which plays an important role in conveying to the customer of that store easily.

Custom product attribute is one of the important characteristics of the products. That is responsible to define the character and specification of the product so the customer easily understands their requirement and influence to buy that product. Examples of product attributes can be any type like product price,  product quantity, product size, etc.

 

Steps to Add Product Attribute Programmatically

In order to create the product attributes we have to follow the following steps, Wishusucess MultipleAttribute module will help you to understand how to add a product attribute in Magento 2.

  • Create file InstallData.php
  • Define the install() method
  • Create custom attribute

 

In the first step, we have to create an InstallData file then in the second step we will define the install method and in the third step, we will add a custom attribute.

 

Magento 2 Add Multiple Product Attribute Programmatically

We will create a file inside of Setup folder with the InstallData file name in the below location.

Wishusucess/ProductAttributes/Setup/InstallData.php

Now the content will look like the below class.

<?php
namespace Wishusucess\ProductAttributes\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'
],
);

$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'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'
],
);

$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'wishusucess_specialproducts',
[
'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'
],
);

$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY, 
'wishusucess_newproducts',
[
'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'
]
);
}
}

 

Step 4: Run Magento 2 Command

Now run the below command

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento c:c

That's it!!

Now go to the Admin > Catalog > Product > Click on any product you will see like the below image.

Add multiple product attribute in Magento 2

The above code will help you to create multiple filter product attribute like best seller attribute, featured attribute, a new attribute, special attribute by using a single file.

 

If you are looking for this complete extension then you can check our GitHub link.

 

Related article

How to Get Data on Frontend From System Configuration File in Magento2

Add JS File in Magento 2 Module: How to Add Java Script

How to Get Data on Frontend From System Configuration File in Magento2

When we create a model inside Magento 2, we also give the system configuration of that model so that the admin user can manage it easily.

System Configuration Data Data in phtml

And any extension or model is considered good only when its user experience is good.

The more you manage or customize the admin side of the extension, the better your admin experience will be.

In this article, I am going to tell you how to create a configuration of System.xml in the admin of any model and get its data in the front end.

 

Get System Configuration Data in Phtml File

The system.xml is a configuration file that is used to manage any extension or module in Magento 2 by giving the option on the admin side to customize or change the behavior.

Configuration options are available in Magento 2

Store -> Settings -> Configuration

 

Step 1: Create Registration File

Here in the first step, you have to create a registration file to register your Magento 2 module or extension.

Wishusucess/SystemHelloworld/registration.php
<?php
/**
* @Developer: Hemant Kumar Singh Magento 2x Developer
* @Website: http://www.wishusucess.com/
*/ 
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_SystemHelloworld',
__DIR__
);

 

Step 2: Create Module XML File

Now you have to create a module XML file to give the module version and basic information of your Magento 2 System configuration module.

Wishusucess/SystemHelloworld/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* @Developer: Hemant Kumar Singh Magento 2x Developer
* @Website: http://www.wishusucess.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Wishusucess_SystemHelloworld" setup_version="1.0.0" active="true"></module>
</config>

 

Step 3: Create System Configuration XML File

The system. xml file is known as the configuration file that we used to create admin configuration fields in Magento 2 Module or extension.

This file decides the admin setting options for any extension or Module.

Store -> Setting -> Configuration
Wishusucess/SystemHelloworld/etc/adminhtml/system.xml
<?xml version="1.0"?>
<!--
/**
* @Developer: Hemant Kumar Singh Magento 2x Developer
* @Website: http://www.wishusucess.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="wus" translate="label" sortOrder="10">
<label>Wishusucess</label>
</tab>
<section id="wishusucess_systemhelloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Hello World</label>
<tab>wus</tab>
<resource>Wishusucess_SystemHelloworld::wishusucess_systemhelloworld</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="text_title" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Title</label>
<comment>This title text.</comment>
</field>
<field id="text_description" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Description</label>
<comment>This is description text.</comment>
</field>
</group>
</section>
</system>
</config>

 

Step 4: Config XML file for Admin

Now we are going to create a config XML file that we used to provide the default value in admin configuration fields in Magento 2 admin.

Wishusucess/SystemHelloworld/etc/config.xml
<?xml version="1.0"?>
<!--
/**
* @Developer: Hemant Kumar Singh Magento 2x Developer
* @Website: http://www.wishusucess.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<wishusucess_systemhelloworld>
<general>
<enable>0</enable>
<text_title>Wishusucess System Config Hello World</text_title>
<text_description>Wishusucess System Configuration Hello World Module</text_description>
</general>
</wishusucess_systemhelloworld>
</default>
</config>

 

Now till here, if you will run the below command then you will see the configuration like below screenshot

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento cache:clean

Magento 2 Create System Configuration

 

Step 5: System Configuration Helper Class

Now here we will get the data from a system XML file, we will initialize the path of each field id of the system.xml file in Magento 2.

In order to initialize the field path, we will prefer the order hierarchy.

Section_id/group_id/field_id
Wishusucess/SystemHelloworld/Helper/Data.php
<?php
/**
* @Developer: Hemant Kumar Singh Magento 2x Developer
* @Website: http://www.wishusucess.com/
*/
namespace Wishusucess\SystemHelloworld\Helper;
use Magento\Framework\App\Config\ScopeConfigInterface;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{

/**
* Admin configuration paths
*
*/
const IS_ENABLED = 'helloworld_config/general/enable';

const TEXT_TITLE = 'helloworld_config/general/text_title';

const TEXT_DESCRIPTION = 'helloworld_config/general/text_description'; 
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;

/**
* Data constructor
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
parent::__construct($context);

}

/**
* @return $isEnabled
*/
public function isEnabled()
{
$isEnabled = $this->scopeConfig->getValue(self::IS_ENABLED, 
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

return $isEnabled;
}

/**
* @return $textTitle
*/
public function getTextTitle()
{
$textTitle = $this->scopeConfig->getValue(self::TEXT_TITLE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

return $textTitle;
}

/**
* @return $textDescription
*/
public function getDisplayText()
{
$textDescription = $this->scopeConfig->getValue(self::TEXT_DESCRIPTION,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

return $textDescription;
}

}

 

Step 6: Call Helper in Block Class

Here, we have to create a block class in order to call the helper. So that we can directly use the block function in the phtml file.

Wishusucess/SystemHelloworld/Block/AdminConfiguration.php
<?php
/**
* @Developer: Hemant Kumar Singh Magento 2x Developer
* @Website: http://www.wishusucess.com/
*/
namespace Wishusucess\SystemHelloworld\Block;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Wishusucess\SystemHelloworld\Helper\Data;
use Magento\Framework\App\Config\ScopeConfigInterface;

class AdminConfiguration extends \Magento\Framework\View\Element\Template
{ 
public function __construct(
\Magento\Backend\Block\Template\Context $context,
Data $helper,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, 
array $data = []
)
{ 
$this->helper = $helper;
$this->scopeConfig = $scopeConfig;
parent::__construct($context, $data);
}

/*
* @return bool
*/
public function isEnabled()
{
return $this->helper->isEnabled();
} 
/*
* @return string
*/
public function getDisplayText()
{
return $this->helper->getDisplayText();
} 
}

 

Step 7: Call System Config Value in PHTML File

Now you will call the block method here so that the data of your admin field can be printed.

Another way is that you can directly call the helper class in this file and use its method.

In Magento 2, any system XML fields show the data of the common file ie admin fields on the front end

Wishusucess/SystemHelloworld/view/frontend/templates/helloworld.phtml
<?= $isEnabled; ?>

<?= $getTextTitle; ?>

<?= $getDisplayText; ?>

Or

<?php
$helper = $this->helper('Wishusucess\SystemHelloworld\Helper\Data');
$isEnabled = $helper->isEnabled();
$getTextTitle = $helper->getTextTitle();
$getDisplayText = $helper->getDisplayText();
?>
//Print Text title
<?php echo $getTextTitle; ?>

//Print Text Description 
<?php $getDisplayText; ?>

 

Now make this module enable and save it, then call this phtml in cms page or block if you want to check this simple module in Magento 2.

<p>{{block class="Wishusucess\SystemHelloworld\Block\AdminConfiguration" template="Wishusucess_SystemHelloworld::helloworld.phtml"}}</p>

 

Run the below command and then check

php bin/magento setup:static-content:deploy -f

php bin/magento cache:clean

 

Magento 2 Get Data on Frontend from System XML

That's all !!

If you need any help with Magento 2 extension or module development you can directly contact me.

Thanks

Check with GitHub

 

Similar Posts:

Add JS File in Magento 2 Module: How to Add Java Script

Magento 2 Featured Products: How to Add Featured Products

Add JS File in Magento 2 Module: How to Add Java Script

When we create a magneto model or extension then at that time we also need to use javascript and style sheet file etc.
Let us know how we add js file in Magento 2 or style sheet in  Magento 2 module or extension.

Add JS file in Magento 2

Magento 2 has its own structure to define the javascript and CSS file. So we will follow the same path in order to add the js file to execute JavaScript code.

Here, I am going to explain with an example so I will create a Magento 2 module to add a JS file to execute the code and pass the parameters inside a script.

 

Steps to Add JS File in Magento 2 Module

There are five steps to add the js and CSS file in Magento 2 module.

  • Create or add in the existing module.
  • Create a requirejs-config.js and a JavaScript module file.
  • Create a layout update to add a template that will enable the JavaScript module.
  • Create a template file.

 

Step 1: Create a New Module

app/code/Wishusucess/AddJsfile/registration.php
<?php
/**
* Developer: Hemant Singh Magento 2x Developer
* Website: http://www.wishusucess.com/
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Wishusucess_AddJsfile',
__DIR__
);

 

Step 2: Create a Module XML file

app/code/Wishusucess/AddJsfile/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Wishusucess_AddJsfile" setup_version="0.0.1">
</module>
</config>

 

Step 3: Create requirejs-config.js and a JavaScript

Add the file

app/code/Wishusucess/AddJsfile/view/frontend/requirejs-config.js
var config = {
map: {
'*': {
hello: 'Wishusucess_AddJsfile/js/hello',
}
}
};

 

Step 4: Add JS File in Magento 2 Extension

In this step, we will add the javascript file in Magento 2 extension or module.

And finally, add the file

app/code/Wishusucess/AddJsfile/view/frontend/web/js/hello.js
define([
"jquery"
], function($){
"use strict";
return function(config, element) {
alert(config.message);
}
}
)

 

Step 5: Add XML File

Now we have to create a layout file in order to add a template file so that will enable the JavaScript in that file of the module.

And then add the file catalog_product_view.xml

app/code/Wishusucess/AddJsfile/view/frontend/layout/catalog_product_view.xml
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" template="Wishusucess_AddJsfile::hello.phtml" />
</referenceContainer>
</body>
</page>

Step 6: Create a Template File

So, this template is a frontend view so we can choose any template in order to show the js functionality.

Now, suppose we have a template file hello.phtml and we want to add the javascript in that file so we will add in the file like below.

 app/code/Wishusucess/AddJsfile/view/frontend/templates/hello.phtml
<div data-mage-init='{"hello": {"message": "Hello Wishusucess Magento Team!"}}'>
Content
</div>

 

Step 6: Run Below Magento 2 Command

Now we have to run the below upgrade and cache command in Magento 2 root directory.

bin/magento setup:upgrade

bin/magento cache:clean

 

Read more: System XML File: How to Create Admin Configuration in Magento 2

 

Add CSS File in Magento 2 Module

In this step, we will learn how we can add the style sheet in Magento 2 extension or Module.

In order to add the CSS file in the Module. first, we will create a CSS file.

app/code/Wishusucess/AddJsfile/view/frontend/web/css/cssfilename.css

 

Recommended Post:

Magento 2.4 Installation Guide: How to Install Magento 2.4.2

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

System XML File: How to Create Admin Configuration in Magento 2

When we create a model or extension, then its control should be given in the admin configuration by using the system XML file, this is a better model and extension scale, which decides how better the model or extension that you have created is.

In Magento 2 there is one file that is System.xml that is used to create admin configuration fields.

This file we need when we want to provide some setting option inside of the admin configuration for admin users.

Store > Setting > Configuration

 

Step 1: Register Extension

In order to create a menu in Magento 2 extension first, you have to create a registration.php file inside of the module folder.

Wishusucess/Conf/registration.php
<?php
/**
* @Category Wishusucess
* @Package Wishusucess_Conf
* @website http://www.wishusucess.com/
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_Conf',
__DIR__
);

 

Step 2: Module information and Version

The module XML file consists of the basic information of your extension. This is one of the most basic files of the Magento 2 extension.

In the Wishusucess module’s root directory, I have created a new directory that is called the, etc directory. So here I have created a file that is module.xml file under the etc directory.

Wishusucess/Conf/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* @Category Wishusucess
* @Package Wishusucess_Conf
* @website http://www.wishusucess.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Wishusucess_Conf" setup_version="2.1.0" />
</config>

 

Read more: Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

Step 3: Create Adminhtml Menu XML File

To Create Admin Menu in Magento 2 extension we need to create the menu XML file.

This is the file about the routing and navigation of the items.

By using this link we can navigate to the other page. These files are used to create a link that helps to the landing on another page that is added in the left navigation and tells Magento framework how to resolve requests for that page.

The menu.xml file gives us options to add items in the content section of the left navigation.

Each item we use to add by action attribute and that action can be decided by the Magento 2 developers, where they want to redirect after clicking the link.

Wishusucess/Conf/etc/adminhtml/menu.xml
<?xml version="1.0"?>
<!--
/**
* @Category Wishusucess
* @Package Wishusucess_Conf
* @website http://www.wishusucess.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Wishusucess_Conf::conf" title="Wishusucess" translate="title" module="Wishusucess_Conf" sortOrder="20" resource="Wishusucess_Conf::conf"/>
</menu>
</config>

 

Add Menu Items in Magento 2 Extension

Now, we can add the menu item from the other module to another module or

We can add the menu item in the same file of

Wishusucess/Conf/etc/adminhtml/menu.xml

But here,

I am adding the menu item from another module. So I am creating a menu file

Wishusucess/Recaptcha/etc/adminhtml/menu.xml
<?xml version="1.0"?>
<!--
/**
* Tech9logy
* @category Recaptcha
* @package Wishusucess_Recaptcha
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Backend/etc/menu.xsd">
<menu>
<add id="Wishusucess_Recaptcha::view" title="Google reCaptcha" translate="title" module="Wishusucess_Recaptcha" sortOrder="10" resource="Wishusucess_Recaptcha::view"/>
<add id="Wishusucess_Recaptcha::grid" title="reCAPTCHA Configuration" module="Wishusucess_Recaptcha" sortOrder="20" parent="Wishusucess_Recaptcha::view" action="adminhtml/system_config/edit/section/wishusucess/" resource="Wishusucess_Recaptcha::view"/>
</menu>
</config>

 

After executing the setup upgrade command you will see the output like the below image.

Magento 2 Menu xml

 

Steps to Create Admin Configuration By System XML File

We have to create a file inside of etc/adminhtml/system.xml then we can

Step 2: Set default value

Step 3: Flush Magento cache

Step 4: Get value from the configuration

Magento 2 System XML File for Admin Configuration

The System configuration page is logically divided into four parts:

  • Tabs
  • Sections
  • Groups
  • Fields.

Now if you will see the admin you can see the menu item which I have added here,

Now, adding system XML file and linking the Recaptcha configuration with system configuration via menu item link.

Wishusucess/Recaptcha/etc/adminhtml/system.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="recaptcha" translate="label" sortOrder="10">
<label>Wishusucess</label>
</tab>
<section id="wishusucess_recaptcha" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>reCAPTCHA Setting</label>
<tab>recaptcha</tab>
<resource>Wishusucess_Recaptcha::wishusucess_recaptcha</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>reCAPTCHA Configuration</label>
<field id="enabled" translate="label comment" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="googlesitekey" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Site Key</label>
<comment><![CDATA[Enter Site Key]]></comment>
</field>
<field id="googlesecretkey" translate="label comment" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Secret Key</label>
<comment><![CDATA[Enter Secret Key]]></comment>
</field>
<field id="moduleposition" translate="Module" type="multiselect" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Select Form</label>
<source_model>Wishusucess\Recaptcha\Model\Config\Source\ConfigOption</source_model>
</field>
</group>
</section>
</system>
</config>

Now the output will look like the below image.

 

System XML in Magento 2

So this is the simple way to add the menu item and system XML configurations in the module and extension.

 

Similar Posts:

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

Google reCAPTCHA in Magento 2: How to Add reCaptcha

How to Get Catalog Product Images URL Using REST API

When we create a mobile application using Magento 2 eCommerce then we use rest API to get the catalog product image URL.

This post will give you an idea about how you can get the product image and product URL from the REST API in Magento 2.

As we know without images we can give a greater user experience to our customers on any e-commerce website. Images give clarity about the product so customers get engaged with stores and sales increase.

 

Get Catalog Product Image REST API

This is a step-by-step code to get the product image URLs in Magento 2 eCommerce store.

This is useful in all kinds of situations like if you are developing a mobile application for your Magento 2 store then you need the product images so in order to show the product image you need to retrieve the image URL.

 

Step 1: Registration of ProductImageApi

first, we have to register our first API by rergistration.php file so we have to create the file in the below location.

Wishusucess/ProductImageApi/registration.php
<?php
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_ProductImageApi',
__DIR__
);

 

Step 2: Create a Module XML file

Wishusucess/ProductImageApi/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Wishusucess_ProductImageApi" setup_version="1.0.2" />
</config>

 

Step 3: Declare Dependency Injection

Wishusucess/ProductImageApi/etc/di.xml
<?xml version="1.0"?>
<!--
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Wishusucess\ProductImageApi\Api\GetProductImage" type="Wishusucess\ProductImageApi\Model\GetProductImageUrl" />
</config>

 

Step 4: Create Web API Route Path

Wishusucess/ProductImageApi/etc/webapi.xml
<?xml version="1.0"?>
<!--
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">
<route url="/V1/getproductimage/:sku" method="GET">
<service class="Wishusucess\ProductImageApi\Api\GetProductImage" method="getProductImageUrl"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>

 

Step 5: Get Catalog Product Image API Model Class

Wishusucess/ProductImageApi/Model/GetProductImageUrl.php

This model class has the actual login, so we have to write the following code in order to get the catalog product image URL.

<?php
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
namespace Wishusucess\ProductImageApi\Model;

use Wishusucess\ProductImageApi\Api\GetProductImage;

class GetProductImageUrl implements GetProductImage {
/**
* @var \Magento\Store\Model\App\Emulation
*/
protected $appEmulation;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @var \Magento\Catalog\Api\ProductRepositoryInterface
*/
protected $productRepository;
/**
* @var \Magento\Catalog\Helper\Image
*/
protected $imageHelper;
/**
* @param \Magento\Store\Model\App\Emulation $appEmulation
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param \Magento\Catalog\Helper\Image $imageHelper
*/
public function __construct(
\Magento\Store\Model\App\Emulation $appEmulation,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
\Magento\Catalog\Helper\Image $imageHelper
) {
$this->appEmulation = $appEmulation;
$this->storeManager = $storeManager;
$this->productRepository = $productRepository;
$this->imageHelper = $imageHelper;
}
public function getProductImageUrl($sku) {
$storeId = $this->storeManager->getStore()->getId();
$product = $this->productRepository->get($sku);
$this->appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);
if (!$product) {
$response = [
[
"code" => '301',
"message" => "SKU " . $productSku . " Not Found On Magento",
],
];
return $response;
} else {
$image_url = $this->imageHelper->init($product, 'product_base_image')->getUrl();
$response = [
[
"product_image_url" => $image_url,
],
];
return $response;
}
$this->appEmulation->stopEnvironmentEmulation();
}
}

 

Step 6: Images URL API Class

Wishusucess/ProductImageApi/Api/GetProductPage.php
<?php
/**
* Category: Wishusucess_ProductImageApi
* Developer: Hemant Singh Magento 2x Developer
* Website: http://wwww.wishusucess.com
*/
namespace Wishusucess\ProductImageApi\Api;
interface GetProductImage {
/**
* @api
* @param string $sku
* @return array
*/
public function getProductImageUrl($sku);
}

 

That's it.

Now, we execute the following command.

php bin/magento s:up
php bin/magento s:s:d -f
php bin/magento c:c

Now you can test your product images rest API on the postman by hitting the web route URL.

Get Catalog Product Images URL

 

Now you can see the above images, here

The method is POST and the route URL path for the rest of API is your store URL address and the method and the product that you want the images path details.

https://www.your_store_url.com/rest/V1/products/sku

or

https://www.your_store_url.com/rest/V1/getproductimage/sku

GitHub Wishusucess

 

Online Help & Support for Magento 2 REST API

If you need any kind of help and support in Magento 2 rest API then you can call me.

I am always available to support you while extension development REST API development or any help related to Magento 2 stores.

I am giving you the helpline details in the below images.

Magento 2 Free Help and Support

 

Similar Post:

Search REST API: How to Find Product in Magento 2 Using REST API

Payment API: How to Make Payment Through REST API in Magento 2

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

If you are looking for the best Magento 2 return & exchange (RMA) Extensions in 2022 then you are on the right page. Here I am going to show you how this RMA extension works.

Wishusucess Magento 2 Return and exchange (RMA) extension are one of the simplest and easily manageable Magento 2 extension that will help you to manage the returned order by the customer.

Our Magento 2 team has developed these Magento 2 RMA extensions based on the market analysis of various factors like usability scores, rating reviews, frontend experience, backend experience, search results, social metrics.

 

Magento 2 Return & Exchange Management

Here, I have added a very simple interface for the admin user so anyone can easily understand the configuration.

A returned merchandise authorization (RMA) ensures to your customer that the product returned by him will also get a refund. And if the customers want to request to replace the item then they can also use the same process to replace the item.

The Wishusucess RMA extension has an admin functionality to approve the request or reject the request or close the request.

In the Magento 2 admin configuration, we have added the option to keep enabling RMA or keep disabling RMA for any products.

RMA Order Management Service

Magento 2 RMA Form Fields

Magento 2 Product Return RMA form fields are given in the admin configuration so anyone can decide the form fields for the frontend customer view.

RMA (Return Merchandise Authorization) form fields can be customizable according to your requirement that will help you to decide easy and optionable form fields for your customer.

Admin > Wishusucess > RMA Form > Manage RMA form

Product Return Management Form Fields

Select Status of Return Order

Each state will send the mail as soon as we change the status.

Magento 2 Return & Exchange

 

Return Order in RMA

This is the dashboard of this extension, where all the returned items will show in the list.

Now admin users can change the status as per their terms and conditions.

This Magento 2 return and management extension has there status options. Whenever we change returned order status of the customer, the mail will be sent to the email details of the customer.

 

Magento 2 Return & Exchange Product

Frontend User:

There is no need to register for the customer so if the customer wants to return the item without registering the account so they can simply fill the RMA form and return the products, and If the customers are registered then they can also use their account to return their products by submitting the RMA form request.

RMA Extension in Magento 2

 

RMA Admin Option:

And admin can approve the request and send the mail to the customer that their request has been successfully accepted. Admin can also reject the request and send the mail that their request has been rejected.

Read more: PayPal Account: How to Create New PayPal Account, Transfer

 

Magento 2 Return & Exchange (RMA) Status

When the customer creates a new request for product return that will show in the admin RMA request as a pending status.

Admin can review requests and decide whether they have to approve or reject RMA return requests.

 

Current RMA Version - 2.1.0

Supported Framework Version - Magento 2.0.x, 2.1.x, 2.2.x,2.3.x, 2.4.x

 

Online Helpline Magento Extension Installation

You can call us anytime for free help and support. We will help you to install this extension and make it compatible with your current version of the Magento 2 store.

Magento 2 Free Help and Support

 

Similar Posts:

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

Google reCAPTCHA in Magento 2: How to Add reCaptcha

Custom SMTP: Magento 2 SMTP Settings for Mail Sending

Many times there is a problem in the mailing system of Magento e-commerce and the mail does not ask at all, that is why the custom SMTP feature has been introduced for Magento 2 which provides convenience in sending your emails.

If an email sent from the Magento 2 store reaches the spam box then there is a need to install a custom SMTP extension. As soon as it is installed, the problem of mail reaching the mail spam box is solved.

Many times we send mail from Gmail, then it does not reach
The main reason for this is the setting of Gmail.

If you haven't turned on Two-Step Verification or Google Mail doesn't allow you to send mail from less secure eCommerce stores, you need to change your settings.

Google Less Secure appTurn on Google Mail Less Secure App

 

Step 1: Install Magento 2 Custom SMTP Extension

First, we have to install the Magento 2 custom SMTP extension in our store, then we have to configure the extension by submitting required details like port number, mailing server, SMTP user id, and password.

Successful testing of SMTP extension will show messages like the below images.

Mageplaza SMTP Configuration

In order to configure the SMTP General Configuration, go to

Stores > Settings > Configuration > Mageplaza > SMTP

Then choose SMTP Configuration

Magento 2 SMTP Configuration

Here, SMTP Username is your email id

and SMTP password is your email id password

Note: Complete the second step in order to send the test mail.

Magento 2 Custom SMTP Testing

Now check your mailbox, you must have received an email that the test was successful.

Mageplaza smtp magento 2

 

Magepal SMTP Configuration in Magento 2

In order to configure magepal Simple Mail Transfer Protocol (SMTP) extension, you have to go into store configuration, after successful configuration, you will be able to send email through a specific third-party mail SMTP server.

mail sending SMTP magepal in Magento 2

 

Online Help for Custom SMTP Configuration in Magento 2

If you need any help in configuring custom SMTP in your Magento 2 website then you can call us, we will configure your Magento 2 store at a fixed rate for this. We charge only 30 dollars and that store configuration gets ready within 30 minutes and then you can send your mail from your store.

Email or Skype ID: cs.hemantsingh@gmail.com

Contact Number/WhatsApp: +91-8197565002

 

Step 2: Change Magento 2 Store Email Address

You will receive the mail only after the configured store email addresses in your Magento 2 store.

Here, you have to enter the sender's email address that represents the business representative.

Stores > Setting > Configuration > General > Store Email Address

Magento 2 SMTP store email address

Now your SMTP mail configuration has been done, now you can send mail from your Magento 2 stores.

 

 

Similar Posts:

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

Google reCAPTCHA in Magento 2: How to Add reCaptcha

Your Session Has Expired Error in Magento 2 While Add to Cart Product

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

Many times we have to keep or remove fields of the customer account form according to our need, then Magento 2 Get Product Total, Subtotal, Coupon, Tax Details Via REST API for that, we have to tamper with the code, which sometimes becomes time-consuming and becomes a bit complicated. So we need a form field manager for Magento 2 stores so that fields can be managed by the admin.

The Wishusucess Magento development team is going to explain the module that will help you to do all this stuff without any problem.

 

Form Field Manager in Magento 2

This fields manager as soon as you install this facility will be available in Magento admin and you can easily remove or apply form fields as per the requirement of your store.

This extension is compatible with all the Magento 2 series like 2.1x, 2.2X, 2.3x, 2.4x.

 

What Does The Magento 2 Form Builder do?

It allows you to easily change or add new custom fields without writing any code.

PayPal Account: How to Create New PayPal Account, Transfer

 

Remove Unnecessary Customer Form Fields:

By using this module you will have the option in admin to add or remove the following customer attributes from the Magento websites.

  • Name Prefix
  • Middle Name/Initial
  • Name Suffix
  • Date of Birth
  • Tax/VAT Number
  • Gender
  • Address Attributes
  • Name Prefix
  • Middle Name/Initial
  • Name Suffix
  • Company
  • Fax
  • VAT Number

 

Minimize Customer Effort While Checkout

By using this, you can reduce unnecessary efforts for your customer during the checkout process.

This way you can use it to help deliver a better and less boring interface for your customers.

As a result, eliminating the fields that are not required for the customer and the data you do not need to collect will both benefit.

This extension is helpful to simplify the no time wasted checkout process.

 

Form Feild Manager Backend

As the Wishusucess fields manager extensions backend, you will have complete access control over all customer address form fields, You will also be able to easily add or remove the form fields. Thus, the customer address fields management becomes quite easier.

Read more: Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

Conclusion

After looking at all the above features, we can finally say that this module provides the best option for the owners to manage the customer account form fields. Customers do not waste time filling the form unnecessarily and their annoyance does not increase.

And helps in completing the checkout quickly.

The cost of this module is $50.

Form Field Manager in Magento 2

 

Similar Posts:

Mobile App Builder Free Extension in Magento 2

Shop By Brand: Magento 2 Shop By Brand Free Extension

Magento 2 Get Product Total, Subtotal, Coupon, Tax Details Via REST API

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

RMA (Return Merchandise Authorization) extension in Magento 2 enables customers to manage returns and exchanges of any product easily.

This also helps Magento 2 websites owners to give the best user experience by giving them a clear, easy, satisfying process so the customer does not get involved with such an unnecessary step that consumes time for customers and stores owners as well.

Products return management in Magento 2 is little bit complex steps so the owners of the website need more time to make it smooth for their customers. The Wishusucess RMA extensions will help you in the proper management of the orders and returns of the products from both the storefront and the admin store side.

RMA Extension in Magento 2

 

RMA (Return Merchandise Authorization) Extension Magento 2

The RMA in Magento product management allows all the customers to return products without a login on their account and order the product without creating an account.

You can show this features link on the footer or header or on the homepage so any customer can see and raise requests conveniently.

 

Compatibility And Installation of RMA

The Wishusucess Magento RMA extension is compatible with the Magento 2.1X, 2.2X, 2.3X, and 2,4X versions.

  • Customers can return any number of purchased products by just submitting their order number and email details.
  • Admin can create a return number from the backend.
  • Magento 2 Store owners can communicate by using this extension.
  • Admin user has the right to change the status of the return package.

RMA Extension in Magento 2

 

RMA Customer And Admin Functionality

The Wishusucess RMA extension in Magento 2 offers similar functionality for both customers and admin that can create the return request of any purchased products.

The customer has to go inside the “My Account” section in order to create a request for the purchased product. and Admin can create a request from the admin menu list of "RMA".

Admin can also track the customer history details of any returned products in the past.

 

How is RMA Extension in Magento 2 beneficial?

Your customers trust your website, even more, when they have a good experience.

You will be able to gain the trust of your customers through our RMA extension and they will make more purchases from your e-commerce website as this extension will go a long way in improving the shopping experience for the customers.

Customers will be able to easily return the wrong product without wasting time in the return process and store owners will be able to make the option of returning the product easy for their customers.

Wishusucess RMA extension in Magento 2 helps you to manage returns and exchanges purchased products by customers on an online store that helps any brand to improve their brand loyalty, customer retention, and customer satisfaction. This extension will also help you to build long-lasting customer relationships with your brand.

Magento 2 Free Help and Support

 

 

Similar Post:

Google reCAPTCHA in Magento 2: How to Add reCaptcha

Shop By Brand: Magento 2 Shop By Brand Free Extension

 

Other Post:

PayPal Account: How to Create New PayPal Account, Transfer

Magento 2.4 Installation Guide: How to Install Magento 2.4.2