Certificated magento

3.20)Is it possible to create an instance of the block and render it on the page without using the Magento layout?

3.20)Is it possible to create an instance of the block and render it on the page  without using the Magento layout?

 Well, you can do something tricky like the following: $block = new Mage_Core_Block_Text()->setText('hello'); $this->getResponse()->appendBody($block->toHtml(); But this is something definitelly not recomended…

Read more

3.21) Is it possible to create an instance of the block and add it to the current layout manually?

3.21) Is it possible to create an instance of the block and add it to the current  layout manually?

 Of course, yes… and in fact this is a common practise by the Magento Team in most of the Admin Controllers. You cad do that with a snippet like the following in any controller: public function indexAction() {       // This loads the Layout (see previous sections)     $this->loadLayout();    ...

Read more

3.22) How are a block’s children rendered? Once you added a child to the block, can you expect it will be rendered automatically?

3.22) How are a block’s children rendered? Once you added a child to the  block, can you expect it will be rendered automatically?

It depends on the type of base block (see the next question for more info about this). Childs may be rendered by calling any of the following Block methods, available in Mage_Core_Block_Abstract:   getChildHtml. Is the most common way of render a child block.   getChildChildHtml. Renders a child of a child...

Read more

3.23) What is a difference in rendering process for different types of blocks?

3.23) What is a difference in rendering process for different types of blocks?

For the main predefined Magento blocks, it works as follow: Mage_Core_Block_Text. This is a simple text block so it is not usual that it has child. If so, they will not be automatically rendered, and you would need to render it manually in code.   Mage_Core_Block_Template. Childs of template based block renders...

Read more

3.24) What is the purpose of each of the following block types

3.24) What is the purpose of each of the following block types

For the main predefined Magento blocks, it works as follow: Mage_Core_Block_Text. This is a simple text block so it is not usual that it has child. If so, they will not be automatically rendered, and you would need to render it manually in code.   Mage_Core_Block_Template. Childs of template based block renders...

Read more

3.26) How can a template’s block instance be accessed inside the template file, and how can other block instances be accessed?

3.26) How can a template’s block instance be accessed inside the template  file, and how can other block instances be accessed?

 The block instance is available from the template block just with the keyword $this, as the template file is included from the block by an include directive.   Other blocks can be accessed by means of the Layout instance, but this is not a good practise except when the accessed block is a child of the current...

Read more

3.27) How can block instances be accessed from the controller?

3.27) How can block instances be accessed from the controller?

Blocks are generated in Magento by the controller as we saw before. You can access the generated blocks by means of the Layout, just as we explained before to be done from the template. $block = $this->getLayout()->getBlock('head'); $block->someMethod();

Read more

3.28) How can block instances be accessed inside install scripts or other model class instances?

3.28) How can block instances be accessed inside install scripts or other  model class instances?

Although this is not a very common way of accessing data, the current Layout is always available by calling: $block = Mage::app()->getLayout()->getBlock('name-of-the-block'); $block->someMethod(); But this is not a common practise. Normal operation would is the other way: Blocks accessing Models to pull some...

Read more

3.29) In which ways can block output be disabled in Magento?

3.29) In which ways can block output be disabled in Magento?

There are some ways you can disable the block output in Magento. Remove a block from the layout in Magento   In the layout files, you can set a remove node to disable the block. This will not only disable the output but also makes the block will not be instantiated. In the layout you can set something like:   <reference...

Read more

3.30) Which method can be overridden to control block output?

3.30) Which method can be overridden to control block output?

As said before, you can override some of the following methdos:   protected function _toHtml() {} protected function _afterToHtml($html) {}

Read more

3.31) Which class performs rendering of the template?

3.31) Which class performs rendering of the template?

The rendering of the block is done by Mage_Core_Block_Abstract, in the final method toHtml(). This method makes three calls that performs rendering and these methods are overriden but each subclass: final public function toHtml() {   . . .   $this->_beforeToHtml();   $html = $this->_toHtml();  ...

Read more

3.32) Which classes are responsible for figuring out the absolute path for including the template file?

3.32) Which classes are responsible for figuring out the absolute path for including the template file?

As we can see in Mage_Core_Block_Template, there is a method that looks for the template file. For this to be done it calls the main design class in Magento: Mage_Core_Model_Design_Package public function getTemplateFile() {     $params = array('_relative'=>true);     $area = $this->getArea();  ...

Read more

3.33) In which method are templates rendered?

3.33) In which method are templates rendered?

Templates are rendered in Mage_Core_Block_Template, in the following method: public function fetchView($fileName) {     . . .        // Templates can be output directly to the browser or its content added to     // the response which at the end of the process is sent to the...

Read more

3.34) How can output buffering be enabled/disabled when templates are rendered?

3.34) How can output buffering be enabled/disabled when templates are rendered?

 Mage_Core_Model_Layout::setDirectOuput(true) public function setDirectOutput($flag) { $this->_directOutput = $flag; return $this; }

Read more

3.35) How are <update />, <block />, and <action /> used in Magento layout?

3.35) How are <update />, <block />, and <action /> used in  Magento layout?

 - <update /> merges another handle into the current handle - <block /> declares a block class - <action /> can call a method of a block with some parameteres

Read more

3.37) How can layout XML files be registered for the frontend and adminhtml areas?

3.37) How can layout XML files be registered for the frontend and adminhtml areas?

In Magento, you may register a new Layout XML file with layout updates by adding this piece of XML to your module config.xml <layout>   <updates>     <anyuniquename>       <file>nv/homelayout.xml</file>     </anyuniquename>   </updates> </layout> If...

Read more

3.38) How can code be modified or added to Magento pages using the following methods?

3.38) How can code be modified or added to Magento pages using the following methods?

−  Template customizations  −  Layout customizations  −  Overriding block classes  −  Registering observers on general block events    Magento is known by its great flexibility to add custom code or modifying the existing one. For that you can explore...

Read more

3.38) In which circumstances are each of the above methods more or less appropriate than others?

3.38) In which circumstances are each of the above methods more or less appropriate than others?

 − Template customizations  −  Layout customizations  −  Overriding block classes  −  Registering observers on general block events 

Read more

3.39) How can variables be passed to the block using the following methods?

3.39) How can variables be passed to the block using the following methods?

−  From layout xml file  −  From controller  −  From one block to another  −  From an arbitrary location (for example, install/upgrade scripts, models)    In Magento, variables can be passed to a block instance in several ways, depending on...

Read more

3.40) In which circumstances are each of the above methods more or less appropriate than others?

3.40) In which circumstances are each of the above methods more or less  appropriate than others?

Probably the most common situations are, for each of the previous cases:   To pass data from a layout file. This is used mainly for block configuration values, like how many items per page will be rendered, how many columns, and so on.   To pass data from a controller. Probably the most used if we talk about...

Read more

3.41) Which block is responsible for rendering JavaScript in Magento?

3.41) Which block is responsible for rendering JavaScript in Magento?

 Both, css and js files in Magento, are managed by the block Mage_Page_Block_Html_Head.   This block has methods for adding files to the html head section of any page in a Magento store. The main method to add files is the following:   function addItem($type, $name, $params=null, $if=null, $cond=null)   The...

Read more

3.42) Which modes of including JavaScript does Magento support?

3.42) Which modes of including JavaScript does Magento support?

  As said before, you can add a file from the js library folder in the root Magento folder, or from the theme, located under/skin/ path.   You can add files both from the layout or directly from code (usually from a controller or another block). Let’s look an example:   From Magento layout file,...

Read more

4.0) Describe the basic concepts of models, resource models, and collections, and the relationship they have to one another

4.0) Describe the basic concepts of models, resource models, and collections, and the  relationship they have to one another

 Here in this post we will discuss how to work with database in Magento. As we know that Magento is enrich with MVC (Model – View – Controller). So we will basically starts with some main concepts of models, resource models, and collections.   Basic concepts of models, resource models, and collections A...

Read more

4.1) Configure a database connection

4.1) Configure a database connection

See here :  http://goweb.vn/kien-thuc-web-vi/thiet-ke-web/40-describe-the-basic-concepts-of-models-resource-models-and...-833.html

Read more

4.2) Describe how Magento works with database tables

4.2) Describe how Magento works with database tables

Magento used the Resource Models to interact with the database tables. When a Model is loaded or saved, it calls its resource model to perform thee operation (executing the database queries). Database table names are configured in config.xml and resource models retrieve them using look-up methods, which allows for the table...

Read more

4.3) Describe the load-and-save process for a regular entity

4.3) Describe the load-and-save process for a regular entity

Loading Data The loading of a model form the database is done using the load($id, $field = null) method. The field argument allows the developer to load the records from a different key. If no field is specified then the resource model identifies the primary key based on the parameters provided to the _init($table, $key)...

Read more

4.4) Describe group save operations

4.4) Describe group save operations

When several save operations have to be performed for an entity, Magento uses database transactions to ensure that the data stays in a consistent state in the database.

Read more

4.5) Describe the role of Zend_Db_Select in Magento

4.5) Describe the role of Zend_Db_Select in Magento

 Magento uses the Zend database abstraction classes like Zend_Db_Select to perform database operations. These classes allow building and executing database queries without having to use the syntax of the specific database engine being used.   When a record is fetched with Zend_Db_Select it...

Read more

4.6) Describe the collection interface (filtering/sorting/grouping)

4.6) Describe the collection interface (filtering/sorting/grouping)

1) Filtering The most important method on a database Collection is addFieldToFilter (addAttributeToFilter when using EAV). This adds your WHERE clauses to the SQL query being used behind the scenes. Consider this bit of code, run against the sample data database (substitute your own SKU is you're using a different set...

Read more

4.8) Describe the role and hierarchy of setup objects in Magento

4.8) Describe the role and hierarchy of setup objects in Magento

Look at here : http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-6-magento-setup-resources

Read more

Q.4.0) Which methods exist to access the table of a resource model?

Q.4.0) Which methods exist to access the table of a resource model?

Class: Mage_Core_Model_Resource: Medthod :getTableName() Class: Mage_Core_Model_Resource_Db_Abstract: Method: getTable()  

Read more

Q.4.1) Which methods exist to create joins between tables on collections and on select instances?

Q.4.1) Which methods exist to create joins between tables on collections and  on select instances?

joinLeft(), joinRight(), joinInner(), joinFull(), joinCross(), joinNatural(), joinStraight() Mage_Core_Model_Resource_Db_Collection_Abstract::join() - Zend_Db_Select::select()

Read more

Q.4.2) How does Magento support different RDBMSs?

Q.4.2) How does Magento support different RDBMSs?

- resource classes make db queries by adapter classes - an adpater contains the concrete db queries

Read more

Q.4.3) How do table name lookups work, and what is the purpose of making table names configurable?

Q.4.3) How do table name lookups work, and what is the purpose of making table names configurable?

- the table name of a resource is defined in the resource model configuration - when a table name changes for an entity every function which requests the entity table name will get the correct one

Read more

Q.4.4) Which events are fired automatically during CRUD operations?

Q.4.4) Which events are fired automatically during CRUD operations?

- model_save_before - model_save_after - model_delete_before - model_delete_after - model_save_commit_after - model_load_before - model_load_after - core_collection_abstract_load_before - core_collection_abstract_load_after And Events are started by $this->_eventPrefix : $this->_eventPrefix . '_save_before' ...

Read more

Q.4.5) How does Magento figure out if a save() call needs to create an INSERT or an UPDATE query?

Q.4.5) How does Magento figure out if a save() call needs to create an  INSERT or an UPDATE query?

 - if the object has no ID and not isObjectNew == true Magento will make an UPDATE - otherwise INSERT  Mage_Core_Model_Resource_Db_Abstract->save     public function save(Mage_Core_Model_Abstract $object)     {         if ($object->isDeleted()) {    ...

Read more

Q.4.6) How many ways exist to specify filters on a flat table collection?

Q.4.6) How many ways exist to specify filters on a flat table collection?

 - Varien_Data_Collection_Db::addFieldToFilter() - ::addFilterToMap() - define own where condition Zend_Db_Select::where()

Read more

Q.4.7)Which methods exist to influence the ordering of the result set for flat table collections? How do the methods differ?

Q.4.7)Which methods exist to influence the ordering of the result set for flat  table collections? How do the methods differ?

 - Varien_Data_Collection_Db::setOrder() - Zend_Db_Select::order() - setOrder takes two parameters: setOrder($field, $direction = self::SORT_ORDER_DESC) More information : http://goweb.vn/kien-thuc-web-vi/thiet-ke-web/46-describe-the-collection-interface-filtering-sorting-group...-839.html

Read more

Q.4.8) Why and how does Magento differentiate between setup, read, and write database resources?

Q.4.8) Why and how does Magento differentiate between setup, read, and  write database resources?

 In magento to Read or Write any query we need database connection. <?php //database read adapter $read = Mage::getSingleton('core/resource')->getConnection('core_read') //database write adapter $write = Mage::getSingleton('core/resource')->getConnection('core_write'); ?> These connections return...

Read more

4.9) Describe the install/upgrade workflow

4.9) Describe the install/upgrade workflow

When having a request, the system will check your module’s version in the    file:/app/code/local/Magestore/Mymodule/etc/config.xml   …  <modules> <Magestore_Mymodule> <version>0.1.3</version> </Magestore_ Mymodule>  </modules>   Magento...

Read more

4.10) Write install and upgrade scripts using set-up resources

4.10) Write install and upgrade scripts using set-up resources

 The Script to install and upgrade the workflow using sql is as below:   <?php $installer = $this; $installer->startSetup(); $installer->run(" DROP TABLE IF EXISTS {$this->getTable(mymodule)}; CREATE TABLE {$this->getTable(mymodule)} ( `mymodule_id` int(11) unsigned NOT NULL auto_increment, `title`...

Read more

4.11)Identify how to use the DDL class in setup scripts

4.11)Identify how to use the DDL class in setup scripts

Have you known much about the DDL class in Magento? This part is intended to answer all frequent questions of usingn the DDL class in setup scripts and obviously makes you more understand about it.   I-What is the DDL?   DDL stands for Data Definition Language or Data Description Language. It’s the language...

Read more

Q.4.9) Under which circumstances are setup scripts executed?

Q.4.9) Under which circumstances are setup scripts executed?

- module needs a setup resource defined in the config.xml - when db version in core_resources is less than the config version the Mage_Core_Model_Resource_Setup looks for an update script - if no db entry exists, it looks for an install script

Read more

Q4.11) Which is the base setup class for flat table entities, and which one the base for EAV entities?

Q4.11) Which is the base setup class for flat table entities, and which one the  base for EAV entities?

- Flat table: Mage_Core_Model_Resource_Setup - EAV table: Mage_Eav_Model_Entity_Setup

Read more