I’ve added a few scripts on my blog, and also over at Branded3 Labs previously, but I’ve not noted how I load them currently.

I’ve dabbled with adding scripts to the shell folder in the past, and this seems like a logical place to keep them sometimes. However, I have got into the habit of using a _script folder in the root of the application.

From this folder, we can include Magento, set up some configuration details, and some helpers, and run some code.

This is a quick example of how to list out all categories in the system.

First, we set the error reporting level so that we can quickly see any issues. If this is being run on production, you’ll probably want to disable this – or, remove the line so that the default setting take over.

Once done, we set a high memory limit, and then, we include the main Magento application file. Once we’ve included the main Magento application file (Mage.php), we have access to all things Magento, and we kick it off by initialising Magento and setting the current store.

Getting a list of categories is easy enough, and we can then manipulate it any way we wish.

Image Credit: kevin dooley