Some question and answer of magento – Which are frequently used in development!

Posted: December 17, 2012 in Magento, Version 1.3.*, Version 1.4.*, Version 1.6.*
Tags: , ,

Some question and answer of magento

How do I get the Magento Home URL?
How do I get the Magento Home Directory?
How do I get the URL of a file in the skin directory?
$this->getSkinUrl(‘images/myfile.png’); // in a template or Block
Mage::getDesign()->getSkinUrl(‘images/myfile.png’); // from anywhere
How do I format a price value?
How do I get the display value of a (multi-)select product attribute?
echo $product->getAttributeText(‘manufacturer’);
How do I create an object instance in magento?
Mage::getModel(‘module/class’); // for models
Mage::helper(‘module/class’); // for helpers
Mage::app()->getLayout()->createBlock(‘module/class’, ‘name_in_layout’); // for blocks
How do I get at GET/POST parameters?
Mage::app()->getRequest()->getParam(‘param_name’); // single parameter
Mage::app()->getRequest()->getParams(); // all parameters
How do I get the Id of the curent store view?
How do I get all Store Views?
Mage::app()->getStores(); // pass true to include the admin store view, too
How do I get the configurable/grouped/bundled product a simple product belongs to?
$parentProductIds = $simpleProduct->getParentProductIds();
How do I get the simple products assigned to a configurable product?
How do I get an instance of an attribute?
Mage::getSingleton(‘eav/config’)->getAttribute($entityType, $attributeCode)

How to check query of collection?
echo $colleciton->getSelect();// note: this will not work when you use load() to get object of any product/category etc id

How to see which class is used?
echo get_class(Mage::getModel('catalog/product')); // Default it will return Mage_Catalog_Model_Product
echo get_class(Mage::helper('product')); // Default it will return Mage_Catalog_Helper_Product

Here: get_class is php function

I hope this code will help you, Thanks for reading my blog.

Bijal Bhavsar :)


Leave a Reply

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

You are commenting using your 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