CommercePeer Brand Logo


Programmatically: Magento 2 Product Entity

Programmatically: How to create custom Magento extensions

Step 1: Create a new directory for your extension

Create a new directory named MyExtension in the app/code directory of your Magento installation.

Step 2: Create a config.xml file

In the MyExtension directory, create a new file named config.xml. This file will define our extension's configuration.


	
	
    
        
            1.0.0
        
    
	
	

Step 3: Create a module.xml file

In the same MyExtension directory, create a new file named module.xml. This file will define the modules that our extension depends on.


	
	
    
        
            Magento_Core
        
    
	
	

Step 4: Create a etc/module.xml file

In the same MyExtension directory, create a new file named etc/module.xml. This file will define our extension's module declaration.


	
	
    
        
            
        
    
	
	

Step 5: Create a controller

In the MyExtension directory, create a new directory named controllers. Inside this directory, create a new file named IndexController.php.


namespace MyExtension\Controller\Index;

class IndexController extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        // Your code here
        echo "Hello World!";
        exit;
    }
}
	

Step 6: Define the route

In the same controllers directory, create a new file named index.php.


	

    
        
            
            my_module/index
            
        
    

	

LET’S WORK TOGETHER

We love working with Small Businesses, Retailers, Manufacturers. Our team is here to Help.

→ Schedule Free Consultant Now
Copyright © 2024 CommercePeer. All Rights Reserved.