Being an online merchant, you would like to create an eye-catching website page. If you use an eCommerce platform such […]
Magento 2 Extension Development: Step by Step Guide
Magento 2 extension development is big news in the market. We already know that Magneto 2 has helped thousands of e-commerce stores by providing up-level experiences to their customers. It is more mobile-friendly than Magento 1. Magento 2 is developed to support PWAs (Progressive Web Applications). It also acts as a highly developed platform that provides: powerful marketing, smooth management of catalog tools, visual merchandising, stage and preview updates, and search engine optimization. Lately, Magento 2 extensions development took place. This article is meant to highlight the key points. Below we have shared a step-by-step guide of Magento 2 Extension Development.
How to create a custom extension in Magento 2?
In these steps, you will learn how to create a custom extension using a hello world module. Before we start, there are some requirements that we need to look upon.
- You must have the latest Magento 2 version installed in your system.
- You need to disable the Magneto Cache: It needs to be done so that you can save some time on the manual flush system when you make changes in the codes.
- Select developer mode: It lets you see all the errors from Magento’s end.
STEPS DEMONSTRATING MAGENTO 2 EXTENSION DEVELOPMENT
Step 1- Create Extension files and folders for setup and registration
- Create 2 folders: app/code/Ksolves and app/code/Ksolves/Helloworld
In case you don’t have the code folder, then you can create it manually. Here, the extension name is Helloworld and the extension namespace is the Ksolves folder.
- Now with another code, you need to create a module.XML file in the “Helloworld” folder.
- To get this module registered, you need to create a registration.php file in the same helloworld folder.
- Go to Magento 2 root and then run the upgrade command.
Step 2- Create a Controller
- Create a routes.XML file in the “Helloworld” frontend folder by the required coding. With this, we are defining the frontend router. Next, you have to route with the id ‘helloworld’.
- Now you have to create the Index.php controller file in the Helloworld Controller/Index folder.
Step 3- Create a Block
You have to create a simple block class. It has to be created with getHelloworldTxt() method so that you can return the Helloworld string.
- The step to do so is: Create a Helloworld.php file in the Helloworld/Block folder.
Step 4- Create Template and Layout Files
Both template and layout files are placed inside the “View Folder” of your extension. Inside this “View Folder”, you will see three subfolders: Base, Adminhtml, and Frontend.
- The first step is creating a helloworld_index_index.XML file inside the frontend/layout folder of the view folder.
Now you have to create a helloworld.phtml file within the frontend/templates folder.
So, this is it. Just open this URL in your browser: /helloworld/index/index
You will see a page open saying “Hello Ksolves this is your first Hello world Magento extension!” Make sure to use the codes correctly. If you feel that you need an expert to help you with your Magento 2 extension development, then KSolves is the best solution for you. We have Magento experts working in our team who are efficient in their work. We hope this article solves your query about how to create a custom extension in Magento. You can leave comments below if you require further elaboration on the codes. Thank you for reading!
Contact Us for any Query
Email: sales@ksolves.com
Call : +91 8130704295