10 Essential Magento Interview Questions *
Toptal sourced essential questions that the best Magento developers and engineers can answer. Driven from our community, we encourage experts to submit questions and offer feedback.
Hire a Top Magento Developer NowInterview Questions
In Magento 1, how can you change the behavior and extend Magento core functionality? If there are multiple ways, explain their differences and advantages/disadvantages.
There are three ways to override core functionalities:
-
Monkey patches: Because Magento loads modules in a specific order, you can override the modules located in the
core
andcommunity
code pools by copying them into thelocal
code pool. In that case, you will rewrite the whole class. This is the least preferred method. - Rewrites: You can rewrite a function by specifying a class in your config file to rewrite an existing class. In this case, you can extend the parent class and rewrite only one function.
- Observers: Magento throws events when specific actions are done. If there is an event that is thrown before or after the action you want to interact with, you can intercept it and modify it. This is the preferred method.
What are the problems with the following code in a .phtml
file:
<?php
$products = Mage::getModel('catalog_products')
->getCollection()
->addFieldToFilter('price' ['>' => 100]);
?>
<h1>Our products less than $100:</h1>
<ul>
<?php
foreach ($products as $product) {
echo '<li>' . $product->getName() . '</li>';
}
?>
</ul>
Loading a model in a template file is bad practice. The template should be for representational logic only. Respect the MVC architecture.
The title should be translated:
<h1><?php echo $this->__('Our products less than $100') ?> :</h1>
The attribute “name” is not selected:
->addAttributeToSelect('name')
The correct model name is catalog/product
and not catalog_products
.
The correct expression for addFieldToFilter
is :
->addFieldToFilter('price', ['lt' => 100]);
Here is a corrected version:
Block class:
Class Toptal_Test_Block_Demo extends Mage_Catalog_Block_Product_Abstract {
public function getProductsLessThan($price){
return Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('name')
->addFieldToFilter('price', ['lt' => $price]);
}
}
Template file:
<?php $price = 100 ?>
<h1><?php echo $this->__('Our products less than %s', Mage::helper('core')->currency($price , true, false)) ?> :</h1>
<ul>
<?php
/** @var Mage_Catalog_Model_Product $product */
foreach ($this->getProductsLessThan($price) as $product) {
echo '<li>' . $product->getName() . '</li>';
}
?>
</ul>
There are other issues related to visibility, output formatting, base currency, etc. that you should also be careful about.
When flat catalog indexing is running, the data is retrieved through EAV. Therefore performance is slowed down by both the indexing process and overhead due to EAV retrieval. The information from the products is still correct.
Apply to Join Toptal's Development Network
and enjoy reliable, steady, remote Freelance Magento Developer Jobs
The most important rule in Magento is “Do not edit the core.” Therefore, you should not edit the template core files either.
In order to change the current theme CSS, the fastest way is to add your custom CSS to the <head>
of the generated HTML by using the layout update. Edit the local.xml
file located in the layout folder of your theme.
If you want to change the template files and be able to easily reuse the theme, you can create your own theme.
Developer
In this mode, all the files in pub/static/
are symlinks to the original file. Exceptions are thrown and errors are displayed in the front end. This mode makes pages load very slowly, but makes it easier to debug, as it compiles and loads static files every time. Cache can still be enabled.
Default
This default is enabled out-of-the-box. It is a state in between production and developer, as the files are generated when they are needed. I.e. CSS files are generated using several LESS files in several locations. These files will be generated only when they are needed by the front end, and will not be generated again the next time they are needed.
Production
This mode should be enabled for all Magento 2 websites in production, as all the required files are generated and placed in the pub/static
folder.
Dependency injection is a design pattern strategy that relegates the responsibility of injecting the right dependency to the calling module or framework. This is the Hollywood Principle: “Don’t call us, we’ll call you.”
The responsibility of calling the right dependency is no longer handled by the function and respects the SOLID principle.
Its main advantages are that it makes code:
- Easier to test
- Easier to re-use
- Easier to maintain
What is the best way to count the items in a collection? Explain the differences with other method(s).
The best way is to use the method getSize()
. This function will not load the collection each time to count the items but store it. So every time you need this value you will not have to recalculate it. Moreover, it uses the SQL COUNT()
function in order to speed up the counting process. However, if the collection has been modified, this value can become inconsistent.
In contrast, the count()
method will load the collection and count its items every time it is called. This can become very resource demanding.
What does EAV mean? What are the advantages and disadvantages of it, and how does Magento addresses the issues associated with it?
EAV stands for entity-attribute-value. It is the way customers, products, and address data are stored in Magento’s database. In order to retrieve information about a customer (entity), you will need to query three tables. For example, if you need to get the date of birth (attribute) of a customer (entity), you will need to retrieve the customer ID using its email address by querying the customer_entity
table, the dob
attribute ID in the eav_attribute
table, and finally use both the entity ID and attribute ID in order to retrieve the date (value) in the customer_entity_datetime
table.
While this makes it complicated to retrieve a value and requires multiple calls, it makes the system very flexible and allows the user to change the attributes, adding and removing them easily without having to modify the database schema.
In order to make data retrieval faster, Magento uses flat tables that are regenerated using indexes; it allows you to retrieve some values querying only this table.
The efficiency and usability of this model is debatable and is still a subject of great discussion between pro- and anti-EAV camps.
Factory classes are generated when code generation happens. They are created automatically for models that represent database entities.
Factory classes are used to create, get, or change entity records without using the ObjectManager
directly, as its direct usage is discouraged by Magento. (This is because it goes against the principles of dependency injection.)
These classes do not need to be manually defined, but they can be, in case you need to define a specific behavior.
Some parameters are defined by a store and some are defined by a website:
Parameter | Scope |
---|---|
Product settings | Default, Store View |
Product prices | Default, Website |
Product tax class | Default, Website |
Base currency | Default, Website |
Display currency | Default, Store view |
System configuration settings | Default, Website, and Store view |
Root category configuration | Store group |
Orders | Store view |
Customers | Default, Website |
Category settings | Default, Store view |
For example, if you need to define different base currencies, you will need two different websites.
There is more to interviewing than tricky technical questions, so these are intended merely as a guide. Not every “A” candidate worth hiring will be able to answer them all, nor does answering them all guarantee an “A” candidate. At the end of the day, hiring remains an art, a science — and a lot of work.
Why Toptal
Submit an interview question
Submitted questions and answers are subject to review and editing, and may or may not be selected for posting, at the sole discretion of Toptal, LLC.
Looking for Magento Developers?
Looking for Magento Developers? Check out Toptal’s Magento developers.
Adrian Bruce
Freelance Magento Developer
Adrian is a lead and senior developer with over 15 years of experience in all phases of the software development lifecycle (SDLC) and specializing in Magento eCommerce back-end development; he's an Adobe Certified Expert Magento Commerce Developer . Adrian also excels at developing PHP applications and various services (including for the web), systems integration, agile project delivery, performance optimization, CI/CD, and the DevOps processes surrounding these technologies.
Show MoreLaura Robson
Freelance Magento Developer
Laura is a web designer and developer with over a decade of experience designing, building, and maintaining websites. Having worked in multiple London digital agencies and software houses, Laura specializes in WordPress and Shopify but also works with bespoke systems. Hardworking and committed, Laura pays robust attention to detail focusing on mobile-first, responsive web design and a love for achieving UX and CRO results for clients.
Show MoreFrançois-Xavier Degroot
Freelance Magento Developer
François-Xavier has ten years of experience as a software developer in the eCommerce industry. He started his career in the Netherlands, working for a successful agency on several projects. Then after spending a few years in Switzerland, François-Xavier landed in Canada and held technical leadership positions in agencies and a leading video game company while working on international-scale eCommerce projects.
Show MoreToptal Connects the Top 3% of Freelance Talent All Over The World.
Join the Toptal community.