Debugging tips & tricks with Magento Commerce

If you are new to Magento then the vast amount of code to digest can be quite overwhelming. However, here are some tips I’ve learned about over the past on some means to tear down Magento and figure out whats making it work.
Zend_Debug::dump
First off use Zend_Debug::dump($foo); instead of using var_dump($foo); or print_r($foo); it is essentially the same, just a wrapper with pre HTML tag for formatting and escaping of special characters.
More details about
Zend Frameworks dump method.
However there will be times that simply dumping objects to the screen can be too much and cause browser hangups or even crashes. The best practice Ive learned is to always use the getData() method that Magento has built-in to the Varient Object, this way your not getting redundant amounts of data dumped to the screen but only the bits you really care about.
Varien Object getData, debug
Magento also has a built-in debug() method in the Varient Object as well that you can use to display data in a string representation of itself.
Keep in mind debug does NOT always get attached to every object.
More details about the
Varien Object debug method,
Varien Object getData method
Log files
What if your having difficulty displaying things to screen or don’t want any users to see debug output. With this in mind you can also use a built in logging function, similar to Zend_Log and is essentially a wrapper as well. You can find it defined in app/Mage.php.
/**
* log facility (??)
*
* @param string $message
* @param integer $level
* @param string $file
* @param bool $forceLog
*/
public static function log($message, $level = null, $file = '', $forceLog = false)
...
And here is an example:
Mage::Log($foo);
Which will log the output the contents of $foo to /var/log/system.log by default.
You can also specify your own log file with an extra argument, your custom log file will appear in /var/log/mylogfile.log
Mage::log($foo, null, 'mylogfile.log');
You can also use combinations of functions/methods to output the contents of an array for instance:
Mage::log(var_dump($fooArray), null, 'mylogfile.log');
Logging MUST be enabled within the admin: Configuration -> Developer -> Log Settings -> Enabled = Yes
XML Configuration
Most of the time, I have have issues with my XML configurations. Since Magento is very configuration based driven, one improper case or underscore can render things useless. Magento doesn’t validate the XML or throw any errors when such are encountered but rather ignored. The best means I’ve found to figure out whats going on is to display the entire XML built from all XML configurations files with.
header("Content-Type: text/xml");
die(Mage::app()->getConfig()->getNode()->asXML());xDebug
xDebug is probably one of the more well known and most used debugging tools available. If your IDE does support it, I would highly suggest taking the time to get your environments setup so that you can connect and use it. I’m not going to cover the general use and configuration of it, however Classy Llama has a nifty post that helps keep Magento from letting xDebug take over error handling.
Classy Llama’s Enable xDebugs Error Handler
It requires modification to the Core files and cant be extended since the class is final. Make note of your change when doing this, or merely use it on a per need basis and removing it after your done with it. You can also setup your version control to ignore any changes with it.
Built-in PHP functions
If your using a bare bones editor without any type of auto complete looking up available class methods can be a pain digging through Magento’s numerous files and folders. To get all available methods from any class you can use var_export, get_class_methods and get_class in combination.
print "<pre>"; var_export(get_class_methods(get_class($this)));
More details on: var_export(), get_class(), get_class_methods()
You can also use it in combination with Magento’s getData() to display data with key values intact.
print "<pre>"; var_export(array_keys($this->getData()));
Developer Mode
One last tip I’ve been doing lately is modifying index.php and adding ini_set('display_errors', 1); to the condition checking for the developer mode flag: MAGE_IS_DEVELOPER_MODE. By default the display_errors ini_set is commented out. Here is what my change looks like:
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
}
Then use .htaccess SetEnv to enable and disable developer mode per environment:
SetEnv MAGE_IS_DEVELOPER_MODE "true"
If you have any tips or if I missed something please feel free to comment and I’ll add it to the article.
Possibly Related Posts:
- Magento vs X-Cart
- Magento version 2.0 (X.Commerce) and eBay
- Magento Supercharged Development Tools and Links
- Book Review: Magento 1.4 Themes Design by PacktLib
- Magento modules post deployment uninstall & downgrading
11Apr2011
Rules of Magento club

My favorite Movie + Favorite E-Commerce platform: Just having some fun with these, what would be your eight rules of Magento?
First rule of Magento is you do not touch core or base/default.
Second rule you DO NOT touch core base/default.
Third rule when in doubt, flush all caches and rebuild indexes.
Fourth rule XDebug, Zend_Debug and Mage::log are your friends.
Fifth rule keep your name spaces clean.
Sixth rule no indexes, no conversions.
Seventh rule development goes on as long as it has to.
Eighth rule if this your first time modifying magento, You have to forget everything else.
Possibly Related Posts:
- Magento vs X-Cart
- Magento version 2.0 (X.Commerce) and eBay
- Magento Supercharged Development Tools and Links
- Book Review: Magento 1.4 Themes Design by PacktLib
- Magento modules post deployment uninstall & downgrading
01Mar2011
Book Review: Magento 1.4 Development Cook Book by PacktLib

After receiving a copy of this book from PacktLib, I have finally had a chance to go over the book in more detail. With Magento already having released a newer version of 1.5, there are still lots of items within this book that still apply. This book definitely should be considered a “Cook book” with recipes on how to perform certain “baking” tasks within Magento. It really isn’t meant for someone who is wanting more in depth details into the internal workings of the Core of Magento. It is more of a consolidation of collective information available online in one nicely packaged readable book.
Pros:
Overall, the content of the book is in depth in the areas that it is covering. The optimization chapter is probably one of the best examples of this, as it covers many areas of optimization even small to mid size companies will need to harness to keep things responsive enough not to scare off potential customers, since Magento is so resource intensive. It covers everything from Memcache, APC/eAccelerator/XCache, Apache and MySQL optimizations best practices.
Cons:
Since it deals with a release that has been out for months some of the topics covered may not be as relevant, especially now that 1.5 is out. In one chapter there is a WordPress integration portion, where now there is a
WordPress plugin and Magento Modules available that will do a lot of these things for you.
Conclusion:
If you are familiar with Linux environments, setting up Magento and have developed many modules before, you may not find this book very interesting. However with that said, if you do have some familiarity with Magento, Linux and Zend Framework but want to learn more with some walk-throughs on how to perform specific tasks like creating a widget, setting up memcache, etc. then you may find this book helpful and useful. It may be one of the books you would pick up a few times if your just starting to get your feet wet with Magento but I don’t see myself going back to it later on.
Overall my rating would be 4 out 5 stars:
![]()
To pick up a copy of your own both Hard and Electronic:
Magento 1.4 Development Cookbook.
Possibly Related Posts:
- Magento vs X-Cart
- Magento version 2.0 (X.Commerce) and eBay
- Magento Supercharged Development Tools and Links
- Book Review: Magento 1.4 Themes Design by PacktLib
- Magento modules post deployment uninstall & downgrading
25Feb2011
Magento Go: To the Cloud!

What is Magento Stratus? According to the FAQ:
Updated 4/14/2011: Magento Stratus is now Magento Go
A follow up from my questions below answered by Magento staff: Magento Go is a fully-managed service running on a private cloud we’ve built for security & performance. Therefore, we handle all the management. And since its not on Rackspace’s standard cloud, there are no management APIs to expose – only ones from the Magento Go Platform.
Project Stratus is Magento’s next-generation on-demand eCommerce platform. At its core, Stratus is an online version of our award-winning eCommerce platform. Everything you already know and love about the Magento platform is available with this hosted service. Stratus creates more choice for merchants to select the product and platform that best fits their needs. Stratus will empower merchants and developers to customize, modify, extend and integrate a hosted store as if it were their own code running on their own servers … an unprecedented capability in the market today.
It appears both Magento and Rackspace have teamed up to create Magento Stratus. From what I have gathered and speculation it is Magento running on Rackspace cloud services with some integration with the Rackspace cloud API. This site is currently running on Rackspace’s cloud and I have used them in the past for a semi-large social network that served up lots of Videos and Photos. Overall it has come a long way from being “Mosso” with lots of applications and others using it.
Some of the advantages to these that I see are:
- One single Core that will be maintained by Magento themselves. No one else will be able to touch it.
- Upgrades to the Core will be done by Magento or Rackspace to the single Core all stores will share.
- Easier PCI Compliance, and maintenance to stay compliant.
- Ability to increase server hardware capabilities on the fly to handle surges of traffic to stores via Rackspace’s cloud API.
- Rackspace’s Support services.
- Ability to push Media to CDN’s (Content Delivery Networks).
- Cheap bandwidth/hardware.
One question that begs to be answered the most is; How extensible will the code be?
Will 3rd party modules have to be approved to run in the cloud first? Will I be able to extend any part of Magento as if I was hosting the source and database myself? Will there be access to SSH and/or the DB if needed to make a change such as updating PEAR or issuing a SQL Query? Will we have access to use Rackspace’s Cloud API in code if we wish?
I have put in my invite and have received requests back from Magento about it, however they are looking for actual Store owners to go onto the stratus cloud as “Beta” users. Being that I’m just an developer, I haven’t gotten a chance to play with it. If anyone is looking, let me know and we can see what could be worked out.
More details and request an invite:
http://www.magentocommerce.com/stratus
Possibly Related Posts:
- Magento vs X-Cart
- Magento version 2.0 (X.Commerce) and eBay
- Magento Supercharged Development Tools and Links
- Book Review: Magento 1.4 Themes Design by PacktLib
- Magento modules post deployment uninstall & downgrading
10Jan2011
Magento memory leak fix 1.4.x

A memory leak was found and identified in Mageto CE versions 1.4.x and has since been fixed in Magento CE versions 1.5.x. This should help speed up imports and inventory management, if you are currently using Community Edition 1.4.x.
Continue reading »
Possibly Related Posts:
- Magento vs X-Cart
- Magento version 2.0 (X.Commerce) and eBay
- Magento Supercharged Development Tools and Links
- Book Review: Magento 1.4 Themes Design by PacktLib
- Magento modules post deployment uninstall & downgrading
10Jan2011









