Breaking

Followers

Showing posts with label Magento. Show all posts
Showing posts with label Magento. Show all posts

Thursday, 24 September 2020

9/24/2020 12:16:00 am

Magento 2 – Create admin account via command line

Magento 2 provides different ways to create an admin account/user, we can create a new admin user from the admin panel and via the command line (CLI). Here is how to do it via CLI.

To create an admin user, Go to Magento 2 root folder, run the command:

php bin/magento admin:user:create

It will ask you: username, password, email, first, and last name. Fill all the details and the user will be created successfully.

For more information about the above command, you can use

php bin/magento admin:user:create --help

Usage: 
    admin:user:create [options]

Options:

–admin-user=ADMIN-USER(Required) Admin user
–admin-password=ADMIN-PASSWORD(Required) Admin password
–admin-email=ADMIN-EMAIL(Required) Admin email
–admin-firstname=ADMIN-FIRSTNAME(Required) Admin first name
–admin-lastname=ADMIN-LASTNAME(Required) Admin last name
–magento-init-params=MAGENTO-INIT-PARAMSAdd to any command to customize Magento initialization parameters

-h, –help Display this help message
-q, –quiet Do not output any message
-V, –version Display this application version
–ANSI Force ANSI output
–no-ANSI Disable ANSI output
-n, –no-interaction Do not ask any interactive question
-v|vv|vvv, –verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
    Creates an administrator


9/24/2020 12:14:00 am

Magento 2 – System Requirements

Magento is an open-source e-commerce platform written in PHP. It uses multiple other PHP frameworks such as Laminas and Symfony. In order to install Magento 2, a few specific server configurations must meet.

Operating SystemsLinux x86-64
Composer

Composer is required for developers who want to contribute to the Magento 2 codebase or develop Magento extensions.

Web ServersApache 2.2 or 2.4The apache mod_rewrite, mod_version, and env_module module must be enabled. (See Apache)
nginx 1.x(or latest mainline version)
PHP7.1.3+, 7.2.xMagento 2.3
7.0.4Magento 2.1.2 and later
7.0.2, 7.0.6 to 7.1.0Magento 2.1.x (all versions)
Not Supported:
PHP 7.1, 5.4Not Supported
PHP 7.0.5Known issue that affects code compiler.
Required PHP Extensions:
bc-math
curl
gd,
ImageMagick 6.3.7 (or later) or both
intl
mbstring
mcrypt
mhash
openssl
PDO_MySQL
SimpleXML
soap
xml
xsl
zip
Additional configuration:
safe_mode : off
memory_limit : 756M or more
DatabaseMySQL 5.6, 5.7
Compatible with MariaDB and Percona

Tuesday, 14 March 2017

3/14/2017 10:09:00 pm

Step-by-Step Magento Custome Module Development

In this article, step by step, we are going to create our first custom module in magento. Here I assume that, you have already completed the installation of the magento, caching and compilation is turned off and have basic knowledge of the magento module’s directory structure and file system.
Before we start with the actual magento module development, let’s have a bird’s eye view on typical magento directory structure:
- webroot [magento project root directory]
 - app [contains code pools, design, configuration, localization and Mage.php files]
- code [contains the code files]
- community [third party modules]
- core [magento core modules]
- local [local modules]
- design [contains modules templates and layout files]
- adminhtml [contains the templates and layout of admin area]
- frontend [contains the templates and layout of front area]
- install [contains installation files]
- etc [contains the system and modules configuration files]
- local.xml
- config.xml
- modules [module configuration files]
- locale [contains the localization files]
- Mage.php [main entry point of magento framework]
- js [javascript library files]
- lib [external libraries include varien, zend framework, etc.]
- media [contains product, cms images, etc]
- skin [contains the css and js file based on the theme]
- var [contains the system generated directories like cache, report, sessions etc]
- cron.sh [cron to make task automatically]
- index.php [main entry point for php application]
The first question that comes to our mind is where to put our modules’ directories and files – we have three choices: a) in the community directory b) in the core directory c) in the local directory, all three are located under the app directory. In magento these are called code pools.
Let’s have a quick overview of the code pools,
  • Core - The core directory contains the core modules which come with magento community edition release. My advice is to never make direct changes into any of the files in this directory, because when it’s time to upgrade magento to a newer version, all the changes you made will disappear.
  • Community - The community codepool contains the modules from third party developers either downloaded from the magento connect store or installed manually. You should place modules code in this directory if you are planning to upload the module to magento connect store.
  • Local - We put all our projects’ specific modules into the local directory, create one if it is not already present in the code directory.
So, for our HelloWorld module I am going to create files and directories under the local codepool. You can use the community codepool too for this purpose. But before that, let’s see which are the major components of a simple magento module development.
Magento module comprises of the following parts:



  • Block - Block files are used to fetch the data and display it on the template files.
  • Model - The model files contains the business logic
  • Controllers - Controllers handles the incoming request and renders the pages according to the routes defined in the layout files.
  • Helper - Helper files, as the name suggest contains, the common code required in the whole module like (validations, image processing, etc.).
  • Etc - etc directory contains the module configuration files which are in xml format. Basically there are two main files. config.xml and system.xml.
  • Sql - sql directory contains the database query files which are in need for that module.
With this a module in magento should also follow the standard Naming Conventions, which is likeCompanyname_Modulename as in our case it will be Multidots_HelloWorld.
So, let’s do it:
Step 1: Go to the app/etc/modules directory and create the Multidots_HelloWorld.xml file and paste the below code in the file:




    
      
         true
         local
      
    
This XML file tells magento that our module is placed under local codepool and it’s status is active.
You can verify the status of the module in magento admin panel from: System >> Configuration.
From the left sidebar Under the Advanced section click on the Advanced tab, click on DisableModules Output section to expand it, search for the Multidots_HelloWorld module.
If the module is not listed here, please check the Multidots_HelloWorld.xml file or clear the cache from System >> Cache Management.
If there isn’t any problem, then you can see the module enabled; see the below screenshot:



Step 2: Now as our module is enabled on the magento site, next we will start creating the required files and directories one by one.
Firstly, under the local codepool, you need to create the directory with name Multidots, under that create directory HelloWorld.
It will be like /webroot/app/code/local/Multidots/HelloWorld



Step 3: Next we will create etc directory under the app/code/local/Multidots/HelloWorld and create XML file with name config.xml under the etc directory. This file will tell magento everything about the structure of our module.
Put the below code in the config.xml file:

  
    
      0.1.0
    
  
  
    
      
        standard
        
          Multidots_HelloWorld
          helloworld
        
      
    
  

  
    
     admin
     
      Multidots_HelloWorld
      admin_helloworld
     
    
  

- Let’s understand the purpose behind each tag used in this file, /config> is main configuration tag which contains all other tags.
- Next one is /modules> tag, in which we have to put our module tag which will be like /Companyname_ModuleName> and the version of the module in the /version> tag. the module upgradation and versioning is managed on the value in this tag.
- Under the /frontend> tag, there is one element /routers>, and it contains the /helloworld> tag which identifies our module in the magento system.
- /use> will tell magento which router we are using, it can be standard, admin or default.
- tag contains the information about our module and the value in the tag will be used to access our module on frontend.
In our case it will be http://website.com/index.php/helloworld/
There is tag which also contains the same tags we have used in the tag, which is used for the admin configuration of our module.
Step 4 : Till now we have told magento about our module, now let’s do some action, in this step we are going to create a controller file.
Head to /webroot/app/code/local/Multidots/HelloWorld/controllers directory.



-Create IndexController.php file in the controllers directory and put the below code snippet in the file.

-Now type the URL http://website.com/index.php/helloworld/ in your browser and see the magic.



Very easy, wasn’t it 
Here we have created our controller file which inherits its code from the core magento Class Mage_Core_Controller_Front_Action, it is the base front controller file.
-By when we type the module name after the index.php in the browser it will call the Index Action of the IndexController, that means http://website.com/index.php/helloword/ is similar to http://website.com/index.php/helloworld/index/index/.
-To be more confident let’s create another action. Add the below code after the index action in theIndexController.php file.
/**

* Done it again
*
* @access public
* @return void
*/
public function doneintagainAction() {

echo "done it again....!!!!";
}
-Now, type the URL http://website.com/index.php/helloworld/index/doneintagain/, we have created another action successfully. You can add as many action you want in the controller file.
This is it for the frontend part, now let’s see how to create and access the admin part of our module.
Step 5: I am sure you have noticed the below configuration portion in the config.xml file we created in the Step 3 of this tutorial:

  
    
      admin
        
          Multidots_HelloWorld
          admin_helloworld
        
    
  
-This portion in the config.xml file tells magento the name of the router we are going to use in the admin side, which is described as admin_helloword.
-Now, head to the path /webroot/app/code/local/Multidots/HelloWorld/controllers and  create the Adminhtml directory.



-In the config.xml file put the below code after the
tag:

  
    
      Multidots_HelloWorld_Helper
    
  


 
   
     HelloWorld
     100
    
      
        Hello World
        0
        admin_helloworld/adminhtml_index
      
    
   
 
-The above XML part in the config.xml file is required for the admin part. The configuration in the tag will be available for both the frontend and the admin panel.
- tag specifies the path of the helper class in our module.
Step 6: Head to the path /webroot/app/code/local/Multidots/HelloWorld/. Create a new Helper directory there, and in the Helper directory create Data.php file, in the Data.php file add the below code:

The helper class is used to render the menu in the admin panel, which is generated by the XML code in the tags  in the config.xml file
Step 7 : In the Adminhtml directory create IndexController.php file and put the below code snippet in that file.

-Here we have created a controller file which extends the core magento admin Controller file and created an index action same as we had done in the front end part.
Step 8: Now log into your admin panel on the main navigation bar. You will see the new menu Helloworld:



click on the Hello World menu and you will see the message on your monitor screen.



That’s it guys, you have done it 

3/14/2017 09:58:00 pm

Magento Interview Questions for fresher

Magento Interview Questions

There is given Magento interview questions and answers that has been asked in many companies. Let's see the list of top Magento interview questions.

1) What is Magento?

Magento is a feature rich e-Commerce platform created on open-source technology. It provides online merchants with unprecedented flexibility and control over the look, content and functionality of their e-Commerce store.

2) What was the initial release date of Magento?

Magento was initially released on 31st March, 2008.

3) What are the different versions of Magento?

Following are the different versions of Magento:

Magento Enterprise Edition
Magento Community Edition
Magento Professional Edition
Magento .go Edition

4) Explain the architecture of Magento?

The architecture of Magento is a typical PHP MVC (Model-View-Controller) application where the entire controller will be in one folder and all the models in another. Files are grouped together and known as modules in Magento.

5) What technology does Magento use?

Magento uses PHP as a web server scripting language and MySQL as a database.

6) What are the different features of Magento?

Some of the basic features of Magento are:

SEO Friendly
Google sitemap support
Reporting and analytics
Customer accounts
Order management
Site management
Payment
Marketing promotion and tools
International support
Extremely modular architecture

7) What are the limitations of Magento?

There are three reasons to use UNITS in programming:

Magento is written in PHP so it is comparatively slower in performance to other e-Commerce solutions.
Magento requires more space and memory. It can consume gigabytes of RAM during heavy processes.
It becomes complex if it is not using object-oriented programming.

8) How can you enhance the Magento performance?

The first Pascal standard was documented by the author of the Pascal programming language Niklaus Wirth but it was an unofficial Pascal standard.

Disable the Magento log
Disable any un-used modules
Magento Caching
Optimize your image
Optimize your Server
Use a Content Delivery Network (CDN)
Put Stylesheets at the Top
Put Scripts at the Bottom
Avoid CSS Expressions

9) How can you make Magento more secure for the client?

You can use following instructions to make Magento more secure for the client:

Use a strong password and change them at regular interval.
Disable remote access to Magento Connect Manager.
Disable Downloader on production sites.
Restrict access to safe IP addresses.

10) What type of web applications are created in Magento.

Magento is mainly used for shopping cart software.

11) What is EAV in Magento?

EAV stands for Entity Attribute Value. It is a technique that facilitates users to add unlimited columns to their table virtually.

12) How many tables will be created in EAV module in Magento? Name them.

EAV module will create 6 tables in database.

They are as follows:

module
module_datetime
module_decimal
module_int
module_text
module_varchar

13) Explain the difference between EAV and flat model..

EAV database model is fully in normalized form. Each column's value is stored in their respective data type table which makes it more complex as they have to join 5-6 tables even if you need only one detail. In EAV, columns are called attributes.

Flat model uses just one table. It is not normalized and uses more database space. It is not good for dynamic requirements where you may have to add some more columns in future. Its performance is fast as it needs only one query instead of joining 5-6 tables. In flat model, columns are called fields.

14) What are Magento product types?

Magento simple product: It is used for a single item without any specific selectable variations. For example, a pen, copy, etc.
Magento grouped product: It is used for a combination of Magento simple product. For example, a pen and copy together.
Magento configurable product: It is used for a single item with specific selectable variations. For example, a pen with different color options.
Magento virtual product: It is used for a virtual item i.e: non touchable item. For example, reservation, insurance, etc.
Magento bundle product: It is used for a bundle of simple products. For example, laptop with various items such as processor, hard disk, RAM, etc.
Magento downloadable product: It is used for online software items. For example, PowerPoint presentation, MP3 files, servers, etc.

15) Explain the difference between Mage::getModel() and Mage::getSingletone() in Magento.

Mage::getModel(): It creates a new object.
Mage::getSingletone(): It first checks the existence of object and if object doesn?t exist, then it creates a new one.

16) Explain ORM in Magento.

ORM stands for Object Relational Mapping. It is a programming technique used to convert different types of data into objects and vice versa.

There are two types of ORM:

Converts different types of data into objects.
Converts objects to various types of data.

17) Explain different modules in Magento.

Core modules
Commercial modules
Community modules

18) How to change theme for login users?

To change theme for login users,

if(Mage::getSingleton('customer/session')->isLoggedIn()):
Mage::getDesign()->setPackageName('package_name')->setTheme('themename');
endif;

19) How can you add an external JavaScript/ CSS file to Magento?

css/yourstyle.css
or

skin_jsjs/ yourfile.js
skin_csscss/yourstyle. css
20) State the syntax to call a CMS page in your module's PHTML file.

$this->getLayout()->createBlock('cms/block')->setBlockId('blockidentifier')->toHtml();

21) When you need to clear the cache to see the changes made in Magento?

When you have added or modified XML, CSS or JS files.

22) How to run custom query in Magento?

To run custom query,

$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$result=$db->query('SELECT * FROM users where id=4');

23) How to enable product's custom attribute visibility in frontend?

In Manage Attributes section under custom attribute, select Yes for "Visible on Product View Page on Frontend" and "Used in Product Listing".

24) State whether namespace is mandatory while creating a custom module in Magento?

No, namespace is not mandatory while creating custom module.

25) Is it possible to have more than one grid in Magento?

Yes it is possible.

26) List the magic methods in Magento?

Magic methods in Magento:

__get()
__set()
__isset()
__call()
__tostring()
__construct()
__has()
__uns()

27) How many types of sessions are there? Why we use different sessions in Magento?

There are namely three sessions in Magento:

customer session
checkout session
core session
All these sessions are stored in one session only. We use different sessions because sometimes we need to clear only a particular session data and not all session data.

28) How can you reset Magento files and Directory permissions?

To reset Magento files and directory to their default and secure permissions, use the following commands from the directory where Magento is installed.

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

29) How to configure Magento to work with another domain?

To configure Magento to work with another domain, you have to change the Magento base URL option in the admin area.

Follow these steps:
Go to Magento admin area > System > Configuration and click Web on the left menu.
Select unsecure option
Edit the base URL field to change the URL that will be used for normal (HTTP) connections.

30) How will you get first and last item from the collection in Magento?

$collection->getFirstItem() and $collection->getLastItem();

31) Explain the use of namespace in Magento?

Magento core modules are placed in mage namespace, core/Mage/Catalog and all custom modules are placed in local/CustomModule.

You can have more than one module with same name but they need to be placed in different namespaces.

32) Explain handles in Magento?

Handles control the structure of the page to be displayed. It decides which block will be placed where in the page. Handle is called for every page and every page request can have several unique handles.

33) Explain compilation feature in Magento?

Compilation feature allows us to compile all Magento files to create a single include path to increase performance.

34) How to enable Maintenance mode in Magento?

Create a file named as maintenance.flag and upload it to Magento home directory containing following code.

$maintenanceFile = 'maintenance.flag';
 
if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

35) How to convert default currency to others in Magento?

To convert default currency to others, select the currency and import currency rates from System-> Manage currency-> Rates.

Syntax:

$convertedPrice = Mage::helper('directory')->currencyConvert($price, currentCurrency, newCurrency);  

36) Explain Google checkout in Magento.

Magento allows the integration of online stores with Google checkout. Google checkout is the online payments service provided by the Google. It works like PayPal.

37) Explain how to change Magento core API setting?

You have to follow these steps to change Magento core API setting.

Go to Admin menu, choose System -> Configuration
Select Magento Core API on the left side of the Configuration Panel, under Services
Click on to expand the General Settings section
Type name of the Default Response Charset that you want to use
Determine the Client Session Timeout in seconds
Click the Save Config button when completed

38) Can all billing information be managed through Magento?

You can do the following things through client Magento account:

You can update your billing address.
You can add a credit card.
You can view your billing history.
You can add a PayPal account.
You can produce a print ready receipt.

39) What are the advantages of applying Connect Patches in Magento?

In Magento, applying Connect Patches provides following features:

Enable easy installation of packages with installation and overwrite any existing translations for the same time
Enhance security, by default Magento Connect uses HTTP to download extensions instead of FTP
Facilitate the extension developers to create new extensions with a dash character in the name
Magento administrators will be informed now who tries to install an extension with insufficient file system privileges.

40) How to fetch 5 bestsellers products programmatically in Magento?

Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->setPage(1, 5)
->load();

41) What is codePool?

Code pool is a concept to pull the code in Magento structured format. It is specified when you register new module in app/etc/modules/Company_Module.xml

There are 3 codePools in Magento: core, community and local, which reside at app/code/ directory.

CodePools:

_community: It is generally used by 3rd party extensions.

_core: It is used by Magento core team.

_local: Local codePool should be used for in-hour module development and overriding of core and community modules for custom requirement.

Residing directory:

_app

_code

So in short, you can say that codePool helps Magento to locate module inside app/code/ for processing
3/14/2017 09:44:00 pm

Magento Interview questions and answers



Magento Interview questions and answers for freshers as well as experienced developers.

1. Explain Magento’s MVC architecture


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. Example, 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. 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:

2. When you enter the URL (something like http://loca.lho.st/frontname/controller/method/param1/value1/param2/value2), this URL is intercepted by one PHP file called index.php which instantiates Magento application

2. Magento application instantiates Front Controller object
3. Further, front controller instantiates Router objects (specified in module’s config.xml, global tag)
4. Now, Router is responsible to “match” the frontname which is in our URL
5. If “match” is found, it sees controller name and method name in the URL, which is finally called.
6. 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.
7. 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).
8. 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.
9. Block contains PHP logic. It references Models for any data from DB.
10. 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’).
For diagramatic view: click here (courtsey: Alan Storm)

3. 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 (Entity Attribute Value), which is quite complicated and expensive to query.

All Magento Models interacting with 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.

For those who don’t know what EAV is, please read my 3rd answer below.

So, to end up this question,
when you want to get some data in Magento, you call it like this:

Mage::getModel('module/model')->load(1);
where 1 is the primary key id for some Regular/Simple table, while in EAV so many tables are joined to fetch just single row of data.

4. 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 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.

5. Difference between Mage::getSingleton() and Mage::getModel()

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. Popular example is 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. Example is when you want to show records from database.

6. How will you call a CMS page in your module’s PHTML file?

$this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘blockidentifier’)->toHtml();

7. 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.

8. When will you need to clear cache to see the changes in Magento?

When you have added/modified XML, JS, CSS file(s).

9. 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 to Yes.

10. Difference between EAV and flat model

EAV 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.

Flat model 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 database table in 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 flat model.

11. Is it mandatory to give Namespace while creating custom module in Magento?



No

12. How will you override Block/Model/controllers in Magento?

http://ka.lpe.sh/2011/06/08/overriderewrite-magento-core-blocks-and-controllers/

13. How will you add/remove content from core’s system.xml file?

You can do that by overriding system.xml configuration. Examples:


   
       
           
               
                   
               
           
       
   


   
       
           
               
                   
                       
                   
               
           
       
   

14. Can you have more than one Grid in a module?

Yes

15. How will you join flat table and EAV table in Magento?

http://ka.lpe.sh/2013/04/28/magento-join-eav-collection-with-flat-table/

16. How will you enable maintenance mode of your Magento website?

http://ka.lpe.sh/2011/12/31/magento-show-maintenance-mode-page-website-under-construction/

17. What are “magic methods” in Magento?

Magento uses __call(), __get(), __set(), __uns(), __has(), __isset(), __toString(), __construct(), etc. magic methods. You can find more details inside class Varien_Object
For more information about magic methods: http://php.net/manual/en/language.oop5.magic.php

18. How many database tables will Magento create when you make a new EAV module?

Magento creates 6 tables when you create new EAV module. Tables: module, module_datetime, module_decimal, module_int, module_text and module_varchar. one is the main entity table, and rest 5 tables which holds attribute’s data in different data types. So that integer values will go to module_int table, price values to module_decimal, etc.

19. Where will you write your module’s business logic in Magento?

inside Model

34. 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.

20. What are the commonly used block types? What is the special in core/text_list block type.

Commonly used block types: core/template, page/html, page/html_head, page/html_header, page/template_links, core/text_list, page/html_wrapper, page/html_breadcrumbs, page/html_footer, core/messages, page/switch.
Some blocks like content, left, right etc. are of type core/text_list. When these blocks are rendered, all their child blocks are rendered automatically without the need to call getChildHtml() method.

21. What are the different design patterns used in Magento?

http://ka.lpe.sh/2013/02/25/magento-design-patterns/

22. What can you do to optimize Magento performance?

http://ka.lpe.sh/category/performance/

23. Where is the relation between configurable product and it’s simple product stored in database?

In the 2 tables:
catalog_product_relation
catalog_product_superlink_table

24. How will you log current collection’s SQL query?

$collection->printLogQuery(true); OR $collection->getSelect()->__toString();

25. How to get first item or last item from the collection?

$collection->getFirstItem() and $collection->getLastItem();