Some useful and important code in magento

Some useful and important code in magento :-
<?php  
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 $configProduct->getTypeInstance()->getUsedProductCollection($configProduct); Get an instance of an attribute Mage::getSingleton('eav/config')->getAttribute($entityType, $attributeCode); ?>

No comments:

Post a Comment