Jun 19, 2011
kalpesh

Magento: Some important functions

Here I will show you some important functions/methods in Magento that will make your development easy.

Get the path of your magento page.

1
echo $this->getUrl('mypage');

Get the path of the image in your skin folder.

1
echo $this->getSkinUrl('images/yourimage.gif');

Get the product link.

1
echo $this->getProductData()->getProductUrl();

Get the product name.

1
echo $this->htmlEscape($this->getProductData()->getName());

Call a static block in .phtml file.

1
echo $this->getLayout()->createBlock('cms/block')->setBlockId('YOURBLOCKID')->toHtml();

Get Image url of current category.

1
echo $this->getCurrentCategory()->getImageUrl();

Check whether the current category is Top category.

1
echo $this->IsTopCategory();

Get description of current category.

1
echo $this->getCurrentCategory()->getDescription();

Display products list page (list.phtml).

1
echo $this->getProductListHtml();

Display CMS block page.

1
echo $this->getCmsBlockHtml();


Get current store id.

1
echo $storeId = Mage::app()->getStore()->getId();

Get current store name.

1
echo $storeName = Mage::app()->getStore()->getName();

Get current store code.

1
echo $storeCode = Mage::app()->getStore()->getCode();

Get website name.

1
echo $websiteName = Mage::app()->getWebsite()->getName();

Get session id.

1
echo $sessionId = Mage::getModel('core/session')->getSessionId();

Get customer id.

1
echo $customerId = Mage::getModel('customer/session')->getCustomerId();

Get guest id.

1
echo $vistitorId = Mage::getModel('core/session')->getVisitorId();

1 Comment

  • Hey kalpesh .. Nice collection of Magento Functions and nicely grouped in one place .. keep it up..

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Recognition

Magento top 50 contributors

Honor

Contributions