Magento Frequently used fuctions

Magento Home URL
– Mage::getBaseUrl();

Magento Home Directory
– Mage::getBaseDir();

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

Format a price value
– Mage::helper(‘core’)->formatPrice($amount);

Get the display value of a (multi-)select product attribute
– echo $product->getAttributeText(‘manufacturer’);

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

GET/POST parameters
– Mage::app()->getRequest()->getParam(‘param_name’); // single parameter
– Mage::app()->getRequest()->getParams(); // all parameters

Get the Id of the curent store view
– Mage::app()->getStore()->getId();

Get all Store Views
– Mage::app()->getStores(); // pass true to include the admin store view, too

Get the configurable/grouped/bundled product a simple product belongs to
– $simpleProduct->loadParentProductIds();
– $parentProductIds = $simpleProduct->getParentProductIds();

Get the simple products assigned to a configurable product

Get an instance of an attribute
Mage::getSingleton(‘eav/config’)->getAttribute($entityType, $attributeCode);


2 thoughts on “Magento Frequently used fuctions

  1. Pingback: Magento Product and Category Related Functions | Magento For Fresher

  2. Pingback: All Catogory Listing in Magento | Magento For Fresher

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 )

Google+ photo

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


Connecting to %s