0

So I have this script:

<?php     
error_reporting(E_ALL);
ini_set('display_errors', 1);
require('app/Mage.php');
umask(0);

Mage::app();

/* 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

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

your.site.url/test.php

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.

0

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 :

<?php

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

        USAGE;
    }
}

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

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 Aug 22 '17 at 0:07
  • You output it in a console not in a file – PЯINCƏ Aug 22 '17 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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