MAGENTO 1.X – HOW TO CREATE A STANDALONE SCRIPT
In some cases, you would need to create different kind of tasks or processes, regardless the Magento standard flow.
That is when you will need a standalone script, and that’s a simple example of how can we create one.
Create a new file inside root/shell directory called test_script.php with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php require_once(dirname(__FILE__).'/../app/Mage.php'); require_once 'abstract.php'; class Offset101_Shell_Testingscript extends Mage_Shell_Abstract { public function run() { echo "¡Hello world!"; } } Mage::init(); $shell = new Offset101_Shell_Testingscript(); $shell->run(); |
Note: It’s mandatory to create the run() method inside our extended class.
Then, you can run your shell script, on your terminal, with the following command:
1 |
php -f test_script.php |
It would be helpful for you, visiting this following article, where i’m showing many useful code snippets that are pretty common inside Magento shell scripts: