Magento – Functions cheatsheet

General functions

Function Description
$this->getRequest()->getServer(‘HTTP_REFERER’); Get the referer URL

Product related functions

Function Description
$product->getName() Get product name
$product->getSku() Get product sku
Mage::getModel(‘cataloginventory/stock_item’)->loadByProduct($_product)->getQty() Get product stock
$product->getResource()->getAttribute(‘color’)->getFrontend()->getValue($product) Get a product attribute value (like color/size)
$product->isSaleable() checks if a product is salable
$product->isisAvailable() checks if a product type is salable
Mage::getModel(‘catalogrule/rule’)->calcProductPriceRule($product,$product->getPrice()) Gets the product final price after all catalog rules have been applied
$product->getTierPrice(1) Gets the product tier price if can be applied to the customer

Newsletter related functions

Function Description
$subscriber = Mage::getModel(‘newsletter/subscriber’);
$subscriber->subscribe($user_mail);
Add mail to subscribers list

Cache

Function Description
$tags = array(Mage_Catalog_Model_Category::CACHE_TAG); //Category block tag
Mage::app()->cleanCache($tags)
Clean specific cache tag (in this case the category list block)

Product images

Function Description
$_product->getMediaGalleryImages()->getItemByColumnValue(‘label’, ‘LABEL_NAME’)->getUrl() Get the url of a specific produc image given its label

Customer related functions

Function Description
$this->helper(‘customer’)->isLoggedIn() Checks if the customer is logged

Revisions

No comments yet.

Leave a Reply