So I have this script:

ini_set('display_errors', 1);


/* Set our dates */
$fromDate = '2016-05-30 00:00:00';
$toDate = '2019-05-31 00:00:00';

/* Get the collection. Here we set a date range, and ignore cancelled orders. 
   You can filter the collection however you prefer */
$orders = Mage::getModel('sales/order')->getCollection()
    ->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate))
    ->addFieldToFilter('status', array('nin' => array('canceled')));

/* Here you can build an array, write to a CSV etc */
foreach($orders as $order){
    /* get order details (e.g. ID) like this: */
     echo $order->getIncrementId().'<br/>';
    $id = $order->getIncrementId()

    /* you can load the order items, if you need them */
    $items = $order->getAllVisibleItems();    

I am trying to place this in the root of my server so I can run it and print orders to the screen. What should the file extension be .js .php .sh? Also once it's on the root of the server, how can I run it?

2 Answers 2


You can put that code in a PHP file (let's say test.php) and run that file directly from browser like this.


Note: Following two line are unnecessary for what you want to achieve

$id = $order->getIncrementId()

    /* you can load the order items, if you need them */
    $items = $order->getAllVisibleItems();  

I'd recommend removing these line because you just want to get the all order ids from that time interval.


You can do it in shell and after that you execute it via a command line.

First you create a new file in : shell/my_script.php

Add the code bellow on it :


require_once 'abstract.php';

class My_Script extends Mage_Shell_Abstract
    public function run()
        // Your script content her

    // Useful for the script's help message
    public function usageHelp()
        return <<<USAGE
        Usage:  php -f my_script.php -- [options]

        by_date   Sort products by discount ending date
        help       This help


// Here we should instantiate the class to call the script
$shell = new My_Script();

Now you execute the script like this: $ php -f shell/my_script.php

  • How would I see the output of that file? The output is basically a bunch of sales orders.
    – DevAnd
    Commented Aug 22, 2017 at 0:07
  • You output it in a console not in a file
    – PЯINCƎ
    Commented Aug 22, 2017 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.