Magento Interview Questions: Magento developer interview questions. Magento is an open-source e-commerce platform written in PHP.
Q 1. What is Magento ?
Magento is a feature-rich eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store.
Magento intuitive administration interface features/provides powerful marketing, search engine optimization and catalog-management tools to give merchants the power to create sites that are tailored to their unique business needs, Designed to be completely scalable and backed by Variens support network, Magento offers companies the ultimate eCommerce solution.
Magento is an open-source e-commerce platform written in PHP. The software was originally developed by Varien.
Q 2. What is the difference between Mage::getSingletone() andMage::getModel() in Magento ?
- Mage::getSingletone() always finds for an existing object if not then create that a new object.
- Mage::getModel() always creates a new object
The difference between Mage:getSingleton() and Mage::getModel() is that the former one does not create an object if the object for same class is already created, while the later creates new objects every time for the class when it’s called.
Mage::getSingleton() uses the “singleton design pattern” of PHP. If the object is not created, it will create it.
Mage::getSingleton() is mostly used when you want to create an object once, modify it and later fetch from it. A popular example is a session, you first create a session object, and then add/remove values from session across different pages, so that it retains your values (e.g. cart values, logged in customer details, etc.) and doesn’t create new session object losing your last changes.
Mage::getModel() is used when you want to have the fresh data from the database. An example is when you want to show records from the database.
Q 3. Why Magento use EAV database model ?
In EAV database model, data are stored in different smaller tables rather than storing in a single table.
product name is stored in catalog_product_entity_varchar table
product id is stored in catalog_product_entity_int table
product price is stored in catalog_product_entity_decimal table
Magento use EAV database model for easy upgrade and development as this model gives more flexibility to play with data and attributes.
Q 4. How to upgrade to the latest version using Magento Connect?
. Upgrading Magento to the latest version is a fairly simple task. Copy and Paste this key magento-core/Mage_All_Latest VIA Magento Connect where it states Paste extension key to install. This will upgrade Magento to the newest version.
Q 5. Explain about the Modules of Magento?
Magento supports installation of modules through a web-based interface accessible through the administration area of a Magento installation. Modules are hosted on the Magento eCommerce website as a PEAR server. Any community member can upload a module through the website and is made available once confirmed by a member of the Magento team. Modules are installed by entering a module key, available on the module page, into the web based interface.
There are three categories of modules hosted on Magento Connect:
- Core Modules
- Community Modules
- Commercial Modules
Core and Community modules can be installed via the administration area. Commercial module pages provide price information and a link to an external website.
Q 6. What technology used by Magento?
Magento uses PHP as a web server scripting language and the MySQL Database. The data model is based on the Entity-attribute-value (EAV)
model that stores data objects in tree structures, thus allowing a change to a data structure without changing the database definition.
Q 7. What is MVC Architecture in Magento?
First of all, what is MVC?
MVC stands for Model-View-Controller
Any application that separates it’s data access, business logic and user interface is called MVC.
There can be two types of MVC: convention-based and configuration-based
1. cakePHP is convention-based, i.e. you just need to follow the instructions of the core system to get your module ready in just few lines.
2. Magento is configuration-based, i.e. you need to specify each and every thing to your module’s config file in order to get it work.
Magento has controllers (for request/response routing), Block (for rendering content), Model (for business logic), Resource/Mysql4 (for database operations), etc (for module-specific configuration files), Helper (for common functions), sql (for setup scripts), layout (for connecting block with templates for each controller action) and template/.PHTML file (for Presentation i.e. View).
How Magento’s MVC works:
- When you enter the URL (something like http://localhost/frontname/controller/method/param1/value1/param2/value2), this URL is intercepted by one PHP file called index.php which instantiates Magento application.
- Magento application instantiates Front Controller object
- Further, front controller instantiates Router objects (specified in module’s config.xml, global tag)
- Now, Router is responsible to “match” the frontname which is in our URL
- If “match” is found, it sees controller name and method name in the URL, which is finally called.
- Now depending on what is written in action name (method name), it is executed. If any models are called in it, the controller method will instantiate that model and call the method in it which is requested.
- Then the controller action (method) instantiate the Layout object, which calls Block specified for this action (method) name (Each controller action name have block and template file associated with it, which can be found at app/design/frontend or adminhtml/namespace/module/layout/module.xml file, name of layout file (module.xml) can be found in config.xml of that module, in layout updates tag).
- Template file (.phtml) now calls the corresponding block for any method request. So, if you write $this->methodName in .phtml file, it will check “methodName” in the block file which is associated in module.xml file.
- Block contains PHP logic. It references Models for any data from DB.
- If either Block, Template file or Controller need to get/set some data from/to database, they can call Model directly like Mage::getModel(‘modulename/modelname’).
Q 8. What is benefit of namespace (package) in magento?
We can have more than one module with same name but they should be placed in different namespaces.
All magento core modules are contained in mage namespace.
and all custom modules are placed in local/CustomModule
Q 9. How to include CMS block in template file(.phtml)?
Access block’s content from .phtml template file by :
11. How Magento ORM works?
ORM stands for Object Relational Mapping
It’s a programming technique used to convert different types of data to Objects and vice versa.
In Magento, ORM is shown as Model (based on Zend Framework’s Zend_Db_Adapter), which further breaks down to two types of Models.
- First is the “simple” i.e. Regular Models which is nothing but flat table or our regular table structure.
- Second Model is EAV
All Magento Models interacting with a database are inherited from Mage_Core_Model_Abstract class, which is further inherited from Varien_Object.
Difference between two Models is, Simple Model is inherited from Mage_Core_Model_Resource_Db_Abstract
while EAV is inherited from Mage_Eav_Model_Entity_Abstract
11. What is EAV in Magento?
EAV, stands for Entity Attribute Value
, is a technique which allows you to add unlimited columns to your table virtually. Means, the fields which is represented in “column” way in a regular table, is represented in a “row” (records) way in EAV. In EAV, you have one table which holds all the “attribute” (table field names) data, and other tables which hold the “entity” (id or primary id) and value (value for that id) against each attribute.
In Magento, there is one table to hold attribute values called eav_attribute and 5-6 tables which holds entity and data in fully normalized form,
- - eav_entity, eav_entity_int (for holding Integer values),
- - eav_entity_varchar (for holding Varchar values),
- - eav_entity_datetime (for holding Datetime values),
- - eav_entity_decimal (for holding Decimal/float values),
- - eav_entity_text (for holding text (mysql Text type) values).
EAV is expensive and should only be used when you are not sure about number of fields in a table which can vary in future.
To just get one single record, Magento joins 4-5 tables to get data in EAV. But this doesn’t mean that EAV only has drawbacks.
The main advantage of EAV
is when you may want to add table field in future when there are thousands or millions of records already present in your table.
In a regular table, if you add table field with these amount of data, it will screw up your table, as for each empty row also some bytes will be allocated as per data type you select.
While in EAV, adding the table column will not affect the previously saved records (also the extra space will not get allocated!) and all the new records will seamlessly have data in these columns without any problem.
8. How will you call a CMS page in your module’s PHTML file?
9. What is codePool in Magento?
codePool is a tag which you have to specify when registering new module in app/etc/modules/Company_Module.xml
There are 3 codePools in Magento: core, community and local, which are resided at app/code/ directory.
Core codePool is used by Magento core team, Community is generally used by 3rd party extensions and Local codePool should be used for in-hour module development and overriding of core and community modules for custom requirement.
So in short, codePool helps Magento to locate module inside app/code/ for processing.
15. When will you need to clear cache to see the changes in Magento?
When you have added/modified XML, JS, CSS file(s).
17. How will you enable product’s custom attribute visibility in frontend?
In the Manage Attributes
section of the custom attribute, select Visible on Product View Page on Front-end
and Used in Product Listing
19. Difference between EAV and flat model
is entity attribute value database model, where data is fully in normalized form. Each column data value is stored in their respective data type table.
Example, for a product, product ID is stored in catalog_product_entity_int table, product name in catalog_product_entity_varchar, product price in catalog_product_entity_decimal, product created date in catalog_product_entity_datetime and product description in catalog_product_entity_text table. EAV is complex as it joins 5-6 tables even if you want to get just one product’s details. Columns are called attributes in EAV.
uses just one table, so it’s not normalized and uses more database space. It clears the EAV overhead, but not good for dynamic requirements where you may have to add more columns in the database table in the future. It’s good when comes to performance, as it will only require one query to load whole product instead of joining 5-6 tables to get just one product’s details. Columns are called fields in the flat model.
20. Is it mandatory to give Namespace while creating custom module in Magento?
21. Explain different types of sessions in Magento (e.g. customer/session, checkout/session, core/session) and the reason why you store data in different session types?
- Customer sessions stores data related to customer, checkout session stores data related to quote and order. They are actuall under one session in an array.
- So firstname in customer/session will be $_SESSION['customer']['firstname'] and cart items count in checkout/session will be $_SESSION['checkout']['items_count'].
- The reason Magento uses session types separately is because once the order gets placed, the checkout session data information should get flushed which can be easily done by just unsetting $_SESSION['checkout'] session variable.
So that the session is not cleared, just session data containing checkout information is cleared and rest all the session types are still intact.
22. Magento product Type ?
Magento simple products
A Magento simple product is the most used product type for Magento. This is because it’s the most general product type of them all. A Magento simple product should be used for a single item without any specific selectable variations.
Magento grouped products
A Magento grouped product should be used for a combination of Magento simple products. Think about a coffee cup that is sold together with a saucer, a silver spoon, a breakfast plate or whatever. You can’t define a specific price for a Magento grouped product but you can define a discount amount.
Magento configurable products
A Magento configurable product should be used for a single item with specific selectable variations. Think about a coffee cup obtainable in different colors and sizes, a woman’s bag obtainable in different materials, a light boll obtainable in different watts or whatever. Each selectable variation can have its own additional costs.
Magento virtual products
A Magento virtual product should be used for a virtual (not touchable) item. Think about an insurance, a reservation, an extra product guarantee or whatever. A virtual product does not allow selecting a shipping method at checkout simply because there’s nothing to ship.
Magento bundle products
A Magento bundle product should be used for a bundle of simple (or virtual) products which are not to be sold separately. Think about a laptop where the customer can choose various items such as hard disk, processor, internal memory or whatever. Each of these items is simple (or virtual) products but can only be sold within the bundle product.
Magento downloadable products
A Magento downloadable product should be used for online software items. Think about an MP3 file, a PowerPoint presentation, a Magento extension or whatever. A downloadable product does not allow selecting a shipping method at checkout simply because there’s nothing to ship.
23. What is Magento’s Compilation feature?
The Compilation feature of Magento will allow you to compile all files of a Magento installation in order to create a single include path to increase performance. The performance increase is between 25%-50% on page loads. In order to use this tool, the directory 'includes' and the file 'includes/config.php' must both be writable.
Important: Before you make any changes to your Magento installation you should always disable compilation. Once the changes are made, run the compilation process, and then enable it.
24. How to run custom MySql query in Magento ?
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$result=$db->query("SELECT * FROM TABLE_NAME");
25. What are some of the top features of Magento?
- Reporting and Analytics
- Customer Accounts
- Product and Catalogue Browsing
- Site Management
- Search Engine Optimization
- Customer Accounts
- International Support
- Marketing Promotion and Tools
- Order Management