Browsing articles in "Magento frontend"
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.

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

Get the path of the image in your skin folder.

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

Get the product link.

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

Get the product name.

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

Call a static block in .phtml file.

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

Get Image url of current category.

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

Check whether the current category is Top category.

echo $this->IsTopCategory();

Get description of current category.

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

Display products list page (list.phtml).

echo $this->getProductListHtml();

Display CMS block page.

echo $this->getCmsBlockHtml();

Continue reading »

Jun 19, 2011
kalpesh

Magento: Checking customer/admin is logged in or not

The most important part in magento development is to check whether customer is logged in or not in the system. So that you can show specific features and extra privileges to your customers. There are many things that are restricted to the guests, while members can see the special privilege things.

Also if the customer is not logged in, we can show a link like “Log in”; while for logged in customers, we can show link like “Log out”, “My account”, etc. This is already present in Magento, but we may want to add more features to our customers. So here is the code where you can check customer is logged in or not.

This will check whether the customer is logged in the magento system or not.

$session=Mage::getSingleton('customer/session', array('name'=>'frontend') );

if ($session->isLoggedIn()) {
    echo "Welcome, ".$session->getCustomer()->getName();
} else {
    echo "Not logged in";
}

This will check whether admin is logged in or not in a magento site.

$adminsession = Mage::getSingleton('admin/session', array('name'=>'adminhtml'));

if($adminsession->isLoggedIn()) {
    echo "Welcome Admin";
} else {
    echo "Not logged in";
}
Jun 14, 2011
kalpesh

Magento get file paths and URLs

Get URL paths of your magento folder structure – Absolute URL Path

Mage::getBaseUrl() => Gets base url path e.g. http://my.website.com/

Mage::getBaseUrl(‘media’) => Gets MEDIA folder path e.g. http://my.website.com/media/

Mage::getBaseUrl(‘js’) => Gets JS folder path e.g. http://my.website.com/js/

Mage::getBaseUrl(‘skin’) => Gets SKIN folder path e.g. http://my.website.com/skin/

Get DIRECTORY paths (physical location of your folders on the server) – Relative URL Path

Mage::getBaseDir() => Gives you your Magento installation folder / root folder e.g. /home/kalpesh/workspace/magento

Mage::getBaseDir(‘app’) => Gives you your Magento’s APP directory file location e.g. /home/kalpesh/workspace/magento/app

Mage::getBaseDir(‘design’) => Gives you your Magento’s DESIGN directory file location e.g. /home/kalpesh/workspace/magento/design

Mage::getBaseDir(‘media’) => Gives MEDIA directory file path

Mage::getBaseDir(‘code’) => Gives CODE directory file path

Mage::getBaseDir(‘lib’) => Gives LIB directory file path

Get Current URL – whole URL path

Mage::helper(‘core/url’)->getCurrentUrl()

Pages:«1...7891011121314

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

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions