Quick tips for Magento Developers

Share
Posted on February 11th, 2012 | Posted by admin

Here I am presenting a list of some useful code snippets for Magento developers that are required here and there in code development. These are the most frequently used code snippets that can sometimes eat up a lot of your time. So here is the collection…

1. Check if customer is logged in:

if(!Mage::getSingleton('customer/session')->isLoggedIn())
{
 $this->_redirect('customer/account/login/');
}

2. Get current site url:

Quick debugging tip

Share
Posted on February 23rd, 2011 | Posted by admin

You can add items to magento’s system log and exception log in your code. This is very handy for pin-pointing coding errors / problems. Developing for Magento is often hard, especially since it’s not always possibly to have error reporting on (and even when it is on, its hard to find exactly what’s wrong!).

Here’s an example of it’s use:

1) Turn on your logging: Admin > Configuration > Developer > Log Settings > Enabled = Yes

2) Example code snippet where you might find this useful: