This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Join our live AMA on the Future of Page Builders with Brizy's CEO! Register Now →

Essential Magento Functions Cheat Sheet For 2018

Updated on December 24, 2021

2 Min Read
Magento Cheat Sheet

Magento is a robust ecommerce platform that is just right for projects of all complexities. Perhaps because of the all-inclusive code base, creating and editing Magento based code could become a real challenge.

To help out fellow Magento coders, I have compiled the following cheat sheet of the frequently used Magento functions, which are frequently used during Magento Developments. So in no particular order, the following list covers essential Magento functions that will help you take care of basic tasks while writing Magento code.

Get the Store URL

$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

Get the Referer URL

$url = $this->getRequest()->getServer(‘HTTP_REFERER’);

Get Current Page URL

$url = Mage::helper('core/url')->getCurrentUrl();

Get Magento Page URL

$url = $this->getUrl('magentopage');

Get Product URL

$url = $this->getProductData()->getProductUrl();

Get Image From Skin Folder

$url = $this->getSkinUrl('images/yourimage.gif');

Get Image From Skin Folder (Secure Access)

$url = $this->getSkinUrl('images/yourimage.gif', array('_secure'=>true));

Get Checkout Page URL

$url = $this->getCheckoutUrl();

Get Cart Page URL

$url = $this->getUrl('checkout/cart');

Get Current Category

$_category = Mage::getModel('catalog/layer')->getCurrentCategory();

Get Category by ID

$_category = Mage::getModel('catalog/category')->load($category_id);

Get Product by ID

$_product = Mage::getModel('catalog/product')->load($product_id);

Get Product by SKU

$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $product_sku);

Add CSS File in Layout Block

<reference name="name_of_the_block">

 <action method="addItem">



   <params />


Add JS File in Layout Block

<reference name="name_of_the_block">

 <action method="addItem">



   <params />


Remove Block From Old Parent

<reference name="old_parent">

 <action method="unsetChild">




Add Block to New Parent

<reference name="new_parent">

 <action method="insert">




Add CMS Block in Layout Block

<block type="cms/block" name="block_name">

 <action method="setBlockId">




Insert Template File in Layout Block

<block type="cms/template" name="template_name" template="page/html/template_file.phtml"/>

Get Base URL in CMS Pages

<a href="{{base url=''}}"></a>

Get Store URL in CMS Pages

<a href="{{store url=''}}"></a>

Get Media URL in CMS Pages

<a href="{{media url='yourmedia.mp4'}}"></a>

Get Skin URL in CMS Pages

<a href="{{skin url='yourimage.gif'}}"></a>

Call a Magento Block in CMS Pages

{{block type="cms/block" block_id="block_id" template="cms/content.phtml"}}

Load Cache Object

$cache = Mage::app()->getCache();

Save Item in Cache Object

$cache->save($string, $string_key, array($tag), $lifetime);

Retrieve Saved Cache


Remove Saved Cache


Save Session Value

$session_value = "This is example session value.";


Retrieve Session Value

Mage::getSingleton('core/session')->getValue();Remove Session Value


Check Whether Customer is Logged in



As you could probably guess by now, this list does not cover all the functions in the Magento universe. Magento is huge and no single blog post could even begin to cover all the available functions ( people have written entire books on the subject!).

I would recommend that you go through the list carefully while making notes on the usage of individual functions. The best way of improving your Magento code is to explore the core of the Magento platform ( PHP, XML, and PHTML files), to learn more about Magento functions.

Happy coding! 🙂


Share your opinion in the comment section. COMMENT NOW

Share This Article

Fayyaz Khattak

Fayyaz, a passionate Motorbike tourist, works as a Team Lead — Magento Community at Cloudways - A Managed Magento Hosting Platform. His objective is to learn & share about PHP & Magento Development in Community. You can contact him at [email protected]


Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!


Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour


  • 0


  • 0


  • 0


  • 0



For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now