Magento Interview Questions
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.
- 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.
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
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.
- 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’).
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.core/Mage/Catalog
and all custom modules are placed in local/CustomModule
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 class, while EAV is inherited from Mage_Eav_Model_Entity_Abstract.
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).
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.
- 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.
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.
$db = Mage::getSingleton('core/resource')->getConnection('core_write'); $result=$db->query("SELECT * FROM TABLE_NAME");
- Reporting and Analytics
- Customer Accounts
- Product and Catalogue Browsing
- Site Management
- Search Engine Optimization
- Customer Accounts
- International Support
- Marketing Promotion and Tools
- Order Management