Magento 2 Interview Questions and Answers

Question 1: What is difference between Magento 1 and 2?
Magento 2 supports latest PHP versions, which include better security provisions and enhance online store speed because of optimized changes with better speed and performance. Biggest improvement in Magento 2 is the load speed
compared to Magento 1.

Question 2: What is MVC Architecture and how it is implemented in Magento 2?
MVC is the Model-View-Controller architecture that divides an application into 3 components as model, view and controller.
The model handles the data and business logic behind running an application. The view is all you see on an application’s user interface.
The controller handles the user request and provides responses to the view after processing the data inputs with model.
MVC in Magento uses a configuration based system where we have to get a module config file to work providing values
specified in it.

Question 3: What technology stack does Magento 2 use?
Magento uses PHP as a web server language and MySQL for database.
Magento 2 supports latest version of PHP 7. For MySQL, it uses version 5.6 or 5.7.

Question 4: Which command is used to enable or disable a Magento 2 module?
php bin/magento module:enable VendorName_ModuleName

php bin/magento module:disable VendorName_ModuleName

Question 5: How can you create a custom module in Magento 2?
To create a module, You have to create a folder with Namespace/ModuleName inside app/code folder.

It will be like: app/code/VendorName/moduleName

For example: app/code/Magemeta/Test

You have to declare module.xml file inside app/code/Magemeta/Test/etc/module.xml.
You have to declare registration.php file inside app/code/Magemeta/Test/etc/registration.php file

Finally, you need to register the module in Magento environment using following command:
php bin/magento setup:upgrade

Question 6: Which file stores the vendor path?
It is the vendor_path.php located at app/etc/ folder.

Question 7: What are the different deploy modes in Magento 2?
There are following deploy modes:

Default mode: This mode deploys Magento applications on a single server and is not optimized for production.
Developer mode: This mode is used when you’re extending the functionality of your website or customizing it.
Production: This mode is enabled when your website is in production.
Maintenance: This mode prevents access to a Magento website when it is being updated or reconfigured.

Question 8: What is dependency injection in Magento 2?
Dependency injection is used in Magento 2 to replace the Mage class functionality which is used in Magento 1.
It is one of the design pattern in which object 1 can declare its dependencies on object 2, and then object 1 doesn’t have to worry about procuring its own dependency requirements. Object 2 will do that based on desired behaviour or configurations.

Question 9: What is a factory class in Magento 2?
Factory classes are one of the design pattern used in Magento. Factory classes are used to create, change, or get an entity without having to access the object manager since it is discouraged by Magento. These classes are created/generated during code generation and do not need to be manually defined. This code generation happens when we run the following command:
php bin/magento setup:di:compile

Question 10. What are the static blocks in Magento 2?
Static blocks are the ones in which information doesn’t change. These blocks can be added anywhere on any page throughout the Magento store.

Question 11. What are the different design patterns used in Magento 2?
Singleton
Object Manager
Dependancy Injection
Proxy
Observer
Factory Method
Builder
Decorator
Strategy
Composition

Question 12: How can you reset Magento directory & file permissions?
You can reset them by following commands through the root directory where Magento is installed.

find . –type f –exec chmod 644 {} \;
find . –type d –exec chmod 755 {} \;
chmod +x mage

Question 13: What are the Architectural layers used in Magento 2?
Domain layer
Persistence layer
Presentation layer
Service layer

Question 14: What command is used to migrate setup from Magento 1 to Magento 2?
php bin/magento setup:migrate <root-path-to-magento1-installation> <new-version>

Question 15: What is a Service layer in Magento 2?
The service layer provides a bridge between the presentation layer and the domain layer and resource-specific data. This is implemented using service contracts, which are defined using PHP interfaces.

Question 16: What are the escape methods used in Magento .phtml templates?
escapeHtml() // Escape string for HTML context
escapeHtmlAttr()
escapeUrl()
encodeUrlParam()
escapeJs()
escapeCss()

Question 17: What are the different types of Plugins used in Magento 2?
Plugins are the interceptors which are used to intercept any public methods of any class in Magento 2. There are following three types of plugins:
Before
Around
After
You can get more details on plugins on this link

Question 18: What is event observer in Magento 2?
Event observer is one of the design pattern method to extend Magento core functionality. Using events and observers, we can run our custom code in response to a specific Magento event or even a custom event.
You can get more info on observers on this link.

For more details, you can also refer the Magento guide

Leave a Reply