Standalone Magento Scripts


Every now and again its useful to create a small standalone magento scripts, I have used them in the past to quickly update settings, or for creating small export scripts etc. These can be setup anywhere on the server and ran either in the browser or via the command line.

Scripts would need to be in PHP format and they would need to start:

The above script would be located in the root, or same place as the your index.php script as the ‘require_once()’ function contains a relative path to the ‘Mage.php’ file. Once you have included the Mage.php file you can utilise all of the functions, helpers and models from the Magento program in your single standalone script. For example:

The above script is purely for example, and should print out the first SKU code in your database when your run the script in your browser. The above snippet uses the Zend Database Object for querying the database, to read more on the functions of Zend in Magento please click here.

Unknown source


Leave a reply