Magento Themes and Magento Extensions

magento how to debug code

Share

Though this may not be an accurate method to find solutions to bugs in magento. But i thought of sharing my approach:
1. Use the Developer hints. Enable it bu going to System->Configuration->Advanced->Developer->Debug. After that you will have to change “Current Configuration Scope” to “Default Store View”. This can change if you have a custom store view. Set “Template path hints” and “Add Block names to hints”. This will show that template file and the corresponding block responsible for the view in the frontend. And helps in locating the files and fixing issues.
2. Sometimes you may want to see the logs of the exceptions or the errors occurring. So you can enable them from “Log Settings” on the same page as above. This is really helpful.
3. Please note that if you want to add custom logs, you can do that as well, by using this command.

Mage::log(“Exception message here”);

4. While debugging use this

echo “<pre>”;var_dump();exit;

. This will display the array in more formatted way.
5. When you display values, use functions like getData(), getProduct(), getCustomer() to retrieve the values inside the collection object.
6. Do not forget to check the apache or mysql logs also, as sometimes an exception may not be caught in magento if there is no catch statement.
7. Use “View Source” on the web page browser, to see the HTML version of the code
8. Use Firefox browser and firebug to see the code in the frontend browser.
9. Use Webdeveloper to debug JS and CSS issues Web developer
10. When you are working on a custom code, then it may be helpful to cross check the code in the default theme of magento. As that is mostly bug free and is expected to work correctly. You can switch the theme form Admin backend of magento.
11. If you are on linux or mac search files or text in file contents quickly using this post. Believe me this is lot faster than any code editor i have come across.

Comments are closed.