10 Essential Magento Interview Questions *
最优秀的Magento开发人员和工程师可以回答的基本问题. 在我们社区的推动下,我们鼓励专家提交问题并提供反馈.
Hire a Top Magento Developer NowInterview Questions
There are three ways to override core functionalities:
-
Monkey patches:因为Magento以特定的顺序加载模块,所以您可以覆盖位于
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:您可以通过在配置文件中指定一个类来重写一个函数,以重写现有的类. 在这种情况下,您可以扩展父类并只重写一个函数.
- Observers: Magento throws events when specific actions are done. 如果在要与之交互的操作之前或之后抛出了一个事件, you can intercept it and modify it. This is the preferred method.
What are the problems with the following code in a .phtml
file:
getCollection()
->addFieldToFilter('price' ['>' => 100]);
?>
Our products less than $100:
' . $product->getName() . '';
}
?>
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:
__('Our products less than $100') ?> :
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:
类Toptal_Test_Block_Demo扩展Mage_Catalog_Block_Product_Abstract {
public function getProductsLessThan($price){
return Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('name')
->addFieldToFilter('price', ['lt' => $price]);
}
}
Template file:
__('Our products less than %s', Mage::helper('core')->currency($price , true, false)) ?> :
getProductsLessThan($price) as $product) {
echo '- ' . $product->getName() . '
';
}
?>
还有其他与可见性、输出格式、基础货币等相关的问题. that you should also be careful about.
在运行平面目录索引时,通过EAV检索数据. 因此,索引过程和EAV检索带来的开销会降低性能. 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.
要更改当前的主题CSS,最快的方法是将您的自定义CSS添加到 of the generated HTML by using the layout update. Edit the
local.xml
file located in the layout folder of your 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. 它是介于生产和开发之间的一种状态,因为文件是在需要时生成的. I.e. CSS files are generated using several LESS files in several locations. 这些文件只有在前端需要时才会生成, 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.
依赖注入是一种设计模式策略,它将注入正确依赖的责任下放给调用模块或框架. This is the Hollywood Principle: “Don’t call us, we’ll call you.”
调用正确依赖项的责任不再由函数和尊重来处理 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()
. 这个函数不会每次加载集合来计数项目,而是存储它. 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. 但是,如果已修改集合,则此值可能变得不一致.
In contrast, the count()
方法将加载集合并在每次调用时对其项进行计数. 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. 这是客户、产品和地址数据存储在Magento数据库中的方式. 为了检索关于客户(实体)的信息,您需要查询三个表. For example, 如果您需要获取客户(实体)的出生日期(属性), 您需要通过查询客户的电子邮件地址来检索客户ID customer_entity
table, the dob
attribute ID in the eav_attribute
table, 最后使用实体ID和属性ID来检索日期(值) customer_entity_datetime
table.
虽然这使得检索值变得复杂,并且需要多次调用, 它使系统非常灵活,并允许用户更改属性, 无需修改数据库模式即可轻松添加和删除它们.
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.
该模型的效率和可用性是有争议的,并且仍然是支持和反对eav阵营之间进行大量讨论的主题.
Factory classes are generated when code generation happens. 它们是为表示数据库实体的模型自动创建的.
类用于创建、获取或更改实体记录,而无需使用 ObjectManager
directly, as its direct usage is discouraged by Magento. (这是因为它违背了依赖注入的原则.)
These classes do not need to be manually defined, but they can be, in case you need to define a specific behavior.
有些参数由商店定义,有些参数由网站定义:
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 |
例如,如果您需要定义不同的基础货币,则需要两个不同的网站.
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
Tired of interviewing candidates? Not sure what to ask to get you a top hire?
Let Toptal find the best people for you.
Hire a Top Magento Developer NowOur Exclusive Network of Magento Developers
Looking to land a job as a Magento Developer?
Let Toptal find the right job for you.
Apply as a Magento DeveloperJob Opportunities From Our Network
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
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还擅长开发PHP应用程序和各种服务(包括web服务)。, systems integration, agile project delivery, performance optimization, CI/CD, and the DevOps processes surrounding these technologies.
Show MoreLaura Robson
劳拉是一名网页设计师和开发人员,拥有十多年的设计经验, building, and maintaining websites. 曾在多家伦敦数字机构和软件公司工作, 劳拉擅长WordPress和Shopify,但也使用定制系统. Hardworking and committed, Laura pays robust attention to detail focusing on mobile-first, 响应式网页设计以及为客户实现UX和CRO结果的热爱.
Show MoreFrançois-Xavier Degroot
franois - xavier在电子商务行业有十年的软件开发经验. 他在荷兰开始了他的职业生涯,为一家成功的机构工作了几个项目. Then after spending a few years in Switzerland, franois - xavier来到加拿大,在从事国际规模的电子商务项目的同时,在各机构和一家领先的视频游戏公司担任技术领导职务.
Show MoreToptal Connects the Top 3% of Freelance Talent All Over The World.
Join the Toptal community.