Certificated magento

Q.2.12) How and where does Magento find a matching record for the current request?

Q.2.12) How and where does Magento find a matching record for the current  request?

•app/Mage.php (Mage::app()->run()) •app/code/core/Mage/Core/Model/App.php •Init and Dispatch controller ($this->getFrontController()->dispatch()); •app/code/core/Mage/Core/Controller/Varien/Front.php •Chose the router match for dispatch ($router->match($this->getRequest())) •...

Read more

2.8) Describe request routing/request flow in Magento

2.8) Describe request routing/request flow in Magento

 Request flow in Magento:   Request URL - index.php (Mage::run()) - app/Mage.php (Mage::app()->run()) - app/code/core/Mage/Core/Model/App.php + Install module database  (Mage_Core_Model_Resource_Setup::applyAllDataUpdates()) + Init and Dispatch controller ($this->getFrontController()->dispatch()); -...

Read more

Q.2.14) How does the standard router map a request to a controller class?

Q.2.14) How does the standard router map a request to a controller class?

 - the router tries to get the module name from the request - if he can't find a module he checks if request came from admin area - if so he sets the module to 'admin'   - otherwise he returns false   - if he find a modulename from request he searches afterwards for all modules with a matching frontName   -...

Read more

Q.2.15) How does the standard router build the filesystem path to a file that might contain a matching action controller?

Q.2.15) How does the standard router build the filesystem path to a file that might contain a matching action controller?

  the router configuration defines a module for the frontName - the standard router tries to find the module controllers dir by passing that moduleName to the Mage::getModuleDir() method   - he tries than to match the controller name to a file which ends to 'Controller.php' Mage_Core_Controller_Varien_Router_Standard->getControllerFileName()  ...

Read more

Q.2.16) How does Magento process requests that cannot be mapped?

Q.2.16) How does Magento process requests that cannot be mapped?

- if noRoute functionality is enabled the standard router sets the controller action to 'noroute' after he can't find an matching controlller action   - otherwise the request can't be dispatched and after 100 router iterations an exception is thrown

Read more

Q.2.17) After a matching action controller is found, what steps occur before the action method is executed?

Q.2.17) After a matching action controller is found, what steps occur before the  action method is executed?

- Module, Controller and Action names are resetted to the found module ones. Also SetControllerModule is set to the found module name - URL paramaters are added to the request - the request is set to dispatch = true   Mage_Core_Controller_Varien_Router_Standard->match(()    public function match(Zend_Controller_Request_Http...

Read more

2.10) Describe the steps needed to create and register a new module

2.10) Describe the steps needed to create and register a new module

 - Register module by file /app/etc/modules/Magestore_Test.xml - Configure module /app/code/local/Magestore/Test/etc/config.xml, register router for controller can be used. -Create controller  /app/code/local/Magestore/Test/controllers/IndexController.php

Read more

2.11) Describe the effect of module dependencies

2.11) Describe the effect of module dependencies

Module dependencies is a definition which illustrates the action dependencies of a module on another module. A simple example is as below:   <?xml version="1.0> <config> <modules> <Magestore_Bundle> <active>true</active> <codePool>core</codePool> <depends> <Mage_Catalog/> <Magestore_Bundle> <modules> </config>  If...

Read more

2.12) Describe different types of configuration files and the priorities of their loading.

2.12) Describe different types of configuration files and the priorities of their loading.

 config.xml Path: app/code/(codepool)/(NameSpace)/(ModuleName)/etc/config.xml Used to configure module. Defines all models, blocks, classes etc. for the specified module. http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/module_config.xml system.xml System.xml is a configuration file similar...

Read more

Q.2.18) What does "Magento loads modules" mean?

Q.2.18) What does

 - Magento first loads the declared module files which are found in app/etc/modules where each xml file represents a module - after that it loads the module configuration of each module which has all dependencies satisfied and is activated - the modules configuration is directly added to the config tree

Read more

Q.2.19) In which order are Magento modules loaded?

Q.2.19) In which order are Magento modules loaded?

- first comes allways Mage_All - than all base modules which means all other modules of the Mage package - finally the custom modules which are located in community and local pool - after loading the configuration files of each modules the modules gets resorted by their dependencies

Read more

Q.2.21) What are the consequences of one module depending on another module?

Q.2.21) What are the consequences of one module depending on another module?

 - the module which one other module depends on must be loaded first so it must come first in the sort order - also this module must be found respectively being activated

Read more

Q.2.22) During the initialization of Magento, when are modules loaded in?

Q.2.22) During the initialization of Magento, when are modules loaded in?

- after loading baseInit and initializing the Cache - before dispatch

Read more

Q.2.23) Why is the load order important?

Q.2.23) Why is the load order important?

- dependencies - core functionality

Read more

Q.2.24) What is the difference regarding module loading between Mage::run() and Mage::app()?

Q.2.24) What is the difference regarding module loading between  Mage::run() and Mage::app()?

 - Mage::app() doesn't invoke the FrontController dispatch action

Read more

2.13) Identify the steps in the request flow in which

2.13) Identify the steps in the request flow in which

This useful article from the Magento website should cover everything you need to know for this segment: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-4-magento-layouts-blocks-and-templates

Read more

Q.2.24) Which ways exist to specify the layout update handles that will be processed during a request?

Q.2.24) Which ways exist to specify the layout update handles that will be  processed during a request?

- register a layout.xml file - create a handle which is basically the the full action name as a xml node - add handles through observer by "controller_action_layout_load_before" event   <layout> <default> <update handle="add_jquery_first" /> </default>   <add_jquery_first> <action...

Read more

Q.2.25) Which classes are responsible for the layout being loaded?

Q.2.25) Which classes are responsible for the layout being loaded?

 - Mage_Core_Controller_Varien_Action - Mage_Core_Model_Layout_Update - Mage_Core_Model_Layout

Read more

Q.2.26) How are layout xml directives processed?

Q.2.26) How are layout xml directives processed?

- Mage_Core_Controller_Varien_Action::loadLayout() – processes the request to load layout Mage_Core_Model_Layout::__construct() – loads layout xml Mage_Core_Model_Layout_Update::load() – load layout updates by handles

Read more

Q.2.27) Which configuration adds a file containing layout xml updates to a module?

Q.2.27) Which configuration adds a file containing layout xml updates to a  module?

 - the module configuration file: AREA/layout/updates/FILENAME.xml - put the following code in <frontend> or <adminhtml> tag:         <layout>             <updates>                 <module_code>  ...

Read more

Q.2.28) Why is the load order of layout xml files important?

Q.2.28) Why is the load order of layout xml files important?

 - beacuse if handles are getting overwritten

Read more

2.14) Describe how and when Magento renders content to the browser

2.14) Describe how and when Magento renders content to the browser

First, let’s explain a few terms that are frequently used in this article: MVC Action: MVC action is nothing but a method defined in a controller class and mapped with the requested URL. For example: when a category page is requested, the action method called is Mage_Catalog_CategoryController::viewAction(). MVC...

Read more

2.15) Describe how and when Magento flushes output variables using the front controller

2.15) Describe how and when Magento flushes output variables using the front controller

In the function dispatch() of Front_Controller, we will see the code below: Mage_Core_Controller_Varien_Front->dispatch()     public function dispatch()     {         $request = $this->getRequest();           // If pre-configured, check equality...

Read more

Q.2.29) Which events are associated with sending output?

Q.2.29) Which events are associated with sending output?

http_response_send_before - lie in Mage_Core_Controller_Response_Http->sendResponse()  public function sendResponse()     {         Mage::dispatchEvent('http_response_send_before', array('response'=>$this));         return parent::sendResponse();  ...

Read more

Q.2.30) Which class is responsible for sending output?

Q.2.30) Which class is responsible for sending output?

The Mage_Core_Controller_Response_Http class   Magento uses a response object to send all output.   All output is added to this object, and then its sendResponse method is called.

Read more

3.0) How you can use themes to customize core functionality?

3.0) How you can use themes to customize core functionality?

Themes are not really intended to modify core functionality, so if you need to make some in depth modification, you better try to create some custom extension to do so.   Throught themes you can anyway modify some behaviours, specially in two ways:   Modifying layouts of pages you can modify or add new blocks...

Read more

3.1) How can you implement different designs for different stores using Magento themes?

3.1) How can you implement different designs for different stores using  Magento themes?

In Magento you can install as much themes as you need. Also you can group themes inside of packages to take advantage of inheritance by defining one default theme and a number of child ones.   Let’s say you have to stores, then there are two common situations:   If you want to mantain ‘almost’...

Read more

3.2) In which two ways you can register custom theme?

3.2) In which two ways you can register custom theme?

Once you have your theme developed, you need to tell Magento which store and when you want to use your theme.   If you want your theme to be used ‘always’ as your store theme, you may tell Magento to use it from System => Configuration => Design.   There you can define your default package...

Read more

3.3) What is the difference between package and theme?

3.3) What is the difference between package and theme?

Package/Interface: Package(Interface) is a collection of themes that determines the visual output and frontend functionalities of your store. An interface can be assigned on either the website-level and/or store view-level through the admin panel (Learn how to assign an interface to the website/store). Themes: A...

Read more

3.4) What happens if the requested file is missed in your theme/package?

3.4) What happens if the requested file is missed in your theme/package?

Fall back to default theme of the current package. Then fall back to base package default theme . Can also define a third point in the middle of these by defining a custom default theme (with a different name than ‘default’) in admin panel.

Read more

3.5) Which kind of paths (absolute or relative) does Magento use for templates and layout files?

3.5) Which kind of paths (absolute or relative) does Magento use for  templates and layout files?

Magento always use relative paths to be able to make fallback access to other themes and packages.

Read more

3.6) How exactly can Magento define which physical file correspond to certain template/layout to use

3.6) How exactly can Magento define which physical file correspond to  certain template/layout to use

 Magento uses the class Mage_Core_Model_Design_Package to find the exact file name of a template or layout file to use.   All the requests go through following method:   public function getFilename($file, array $params){ Varien_Profiler::start(__METHOD__); $this->updateParamDefaults($params);...

Read more

3.7) Which classes and methods need to be rewritten in order to add additional directories to the fallback list?

3.7) Which classes and methods need to be rewritten in order to add  additional directories to the fallback list?

As far as previous section, you should override Mage_Core_Model_Design_Package and at least the following methods: public function getFilename($file, array $params) {} public function getSkinUrl($file = null, array $params = array()) In that methods, you see an array like the following, which defines the fallback list:   array(  ...

Read more

3.8) What are blocks used for in Magento?

3.8) What are blocks used for in Magento?

Blocks are the main design element in Magento. A hierarchy of blocks is used to layout any page in a Magento store. Blocks in Magento divide into two big groups: Structural Blocks Content Blocks   Programmatically there are no difference between them, but structural blocks are use in Magento to define main areas...

Read more

3.9) What is the parent block for all Magento blocks?

3.9) What is the parent block for all Magento blocks?

All Magento blocks inherits Mage_Core_Block_Abstract that inherits directly from Varien_Object

Read more

3.10) Which class does each block that uses a template extend?

3.10) Which class does each block that uses a template extend?

Any Magento Block that uses a template file, inherits from Mage_Core_Block_Template which inherits from Mage_Core_Block_Abstract

Read more

3.11) In which way does a template block store information about its template file? Does it store an absolute or a relative path to the template?

3.11) In which way does a template block store information about its  template file? Does it store an absolute or a relative path to the  template?

A Magento template block stores the relative path to the template file in a protected variable _template that can be accessed to the corresponding setter and getter methods (setTemplate and getTemplate). Mage_Core_Block_Template->getTemplate()      public function getTemplate()     {  ...

Read more

3.12) What is the role of the Mage_Core_Block_Abstract class?

3.12) What is the role of the Mage_Core_Block_Abstract class?

Mage_Core_Block_Abstract is the base class for all blocks in a Magento store and it provides basic functionallity for working with layout, block hierarchy (insert, remove childs…), output contents, and so on.

Read more

3.13) Can any block in Magento use a template file?

3.13) Can any block in Magento use a template file?

The template file usage in Magento is restricted to Mage_Core_Block_Template and blocks inheriting from it.   Other blocks in Magento like Mage_Core_Block_Text does not inherit from it but from Mage_Core_Block_Abstract so it cannot use a template file for rendering.

Read more

3.14) How does the $this variable work inside the template file?

3.14) How does the $this variable work inside the template file?

In Magento, the template file for each block is ‘included’ by a php include directive during the render phase, so it´s clear that $this inside a template file, always refer to the block class instance.   The include is done in the fetchView() method of Mage_Core_Block_Template.

Read more

3.15) Is it possible to render a template without a block in Magento?

3.15) Is it possible to render a template without a block in Magento?

Well, never knows what’s the correct answer to some like this. This is not possible in a non-tricky way, but you may copy part of the fetchView() to make it works… Definitely not a good practise, but possible any way. The include of a template in a Magento Block is as follows: Mage_Core_Block_Template->fetchView() public...

Read more

3.16) Is it possible to have a block without a template in Magento?

3.16) Is it possible to have a block without a template in Magento?

Of course yes… in fact, the only predefined block class in Magento that uses a template file is Mage_Core_Block_Template. It is the most used, but not the only block class in Magento. Other classes in Magento like Mage_Core_Block_Text or Mage_Core_Block_Text_List doesn’t use a template file.

Read more

3.17) Which class is responsible for creating an instance of the block?

3.17) Which class is responsible for creating an instance of the block?

In Magento, the whole block hierarchy during a page generation is created by the class Mage_Core_Model_Layout. The method generateBlocks is responsible of that. Let’s take a look… Mage_Core_Model_Layout->generateBlocks()  public function generateBlocks($parent=null) {       if (empty($parent))...

Read more

3.18) Which class is responsible for figuring out which blocks should be created for certain pages?

3.18) Which class is responsible for figuring out which blocks should be  created for certain pages?

In Magento, the process of determining which blocks from layout should be created and rendered is a bit complex to summarize in a few lines. Don’t expect to understand this on first reading… Every request to the Magento system, goes through a particular module and controller. In most of controllers, you can...

Read more

3.19) How is the tree of blocks typically rendered?

3.19) How is the tree of blocks typically rendered?

 Following the previous example, the blocks in Magento are rendered when the controller calls to $this->renderLayout(); This method is in the base class of all Magento Controllers, which is Mage_Core_Controller_Varien_Action. Take a look to the most important lines:   public function renderLayout($output='')...

Read more