Posts Tagged ‘question’

Some question and answer of magento

How do I get the Magento Home URL?
Mage::getBaseUrl();
How do I get the Magento Home Directory?
Mage::getBaseDir();
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?
Mage::helper(‘core’)->formatPrice($amount);
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?
Mage::app()->getStore()->getId();
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?
$simpleProduct->loadParentProductIds();
$parentProductIds = $simpleProduct->getParentProductIds();
How do I get the simple products assigned to a configurable product?
$configProduct->getTypeInstance()->getUsedProductCollection($configProduct);
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.

Thanks,
Bijal Bhavsar :)