Question and Answers(part-2)

Q 1. What is benefit of namespace (package) in magento?

Ans. 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
local/Muster/CustomModule

Q 2. What is the difference between Mage::getSingletone() andMage::getModel() in Magento

Ans. Mage::getSingletone() always finds for an existing object if not 
then create that a newobject
 but Mage::getModel() always creates a new object.

Q 3. How to include CMS block in template file(.phtml)?

Ans. Access block's content from .phtml template file by :
echo $this->getLayout()->createBlock('cms/block')
->setBlockId('static_block_id')->toHTML();

Q 4. Why Magento use EAV database model ?

Ans. In EAV database model, 
data are stored in different smaller tables
rather than storing in a single table.
Example: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 5. How to add an external javascript/css file to Magento

Ans.
<action method="addJs"><script>js/yourfile.js</script></action>
 <action method="addCss"><stylesheet>css/yourstyle.css</stylesheet>
</action>
 or
 <action method="addItem"><type>skin_js</type><name>js/ yourfile.js</name>
</action>
 <action method="addItem">
<type>skin_css</type><name>css/yourstyle. css</name>
</action>

Q 6. What technology used by Magento?

Ans. 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 are handles in magento (layout)?

Ans.Handles are basically used for controlling the structure of the page like which block will be displayed and where. First level child elements of the node are called layout handles. Every page request can have several unique Handles. The handle is called for every page.

The muster_index_index handle is created by combining the frontName (muster), Action Controller (index), and Action Controller Action Method (index) into a single string and this handle will be called only when /muster/index/index url is accessed.

<layout version="0.1.0">
 <muster_index_index>
 <reference name="root">
 <block type="page/html" name="root" output="toHtml" 
  template="../somepage.phtml" />
 </reference>
 </muster_index_index>
 </layout>

Q 10. How to get the Total Price of items currently in the Cart?

Ans.helper(‘checkout’)->formatPrice(Mage::getSingleton(‘checkout/cart’)
->getQuote()->getGrandTotal()); ?>

Q 11. How to set different themes for logged in users?

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

Q 12. How to create magento custom module?

Ans. Steps to create custom magento module:
Namespace : Zag
Module Name : Mymodule
1. Create directory Mymodule in app/code/local/Zag
2. Create Block, controllers, etc, Module directories. 
Create controller, block and module file as required.
3. Create module configuration file 
(app/code/local/Zag/Mymodule/etc/config.xml).
4. Create xml file (app/etc/modules/Zag_ Mymodule.xml)
to enable/disable module and tell magento system 
from which code pool that module will be taken.

Q 13. How to set different themes for each store?

Ans. Go to : System>Designs
Then, add new design change or edit existing. 
You can select Store and Custom Design.

Q 14. How to fetch 5 bestsellers products programmatically

Ans.
Mage::getResourceModel(‘reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(‘*’)
->setPage(1, 5)
->load();

Q 15. How to Call a static block in .phtml file.

Ans.

A. Call a static block in .phtml file.
 echo $this->getLayout()->createBlock('cms/block')->setBlockId('YOURBLOCKID')->toHtml();

B. call block directly from phtml file without defining in layout
 echo $this->getLayout()->createBlock(‘newmodule/newblock’)->setTemplate(‘newmodule/newblock.phtml’)->toHtml();   
Advertisements

One thought on “Question and Answers(part-2)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s