0

Trying to gather all the orders (current day) and sum totals

Updated:

    $format = Mage::getModel('core/date')->date('Y/m/d');
    $from = $format.' 00:00:00';
    $now  = Mage::getModel('core/date')->date('Y/m/d H:m:i');

    $torders = Mage::getModel('sales/order')
        ->getCollection()
        ->addAttributeToSort('increment_id', 'DESC')
        ->addFieldToFilter('state',Array('neq'=>Mage_Sales_Model_Order::STATE_NEW))
        ->addAttributeToFilter('created_at', array('from' => $from,'to' => $now))
        ;

everything is fine except one little thing, one of the orders seems to be not in collection.

Checked all customer_emails and the order created just before midnight (00:14:46) is not included in collection for some reason. suppose to be 127 order while getSize() is saying 126 regardless what filters used etc.

Any ideas ?

2

Try this

$from = new DateTime('2017-08-29 00:00:00');
$from = $from->format('Y-m-d H:i:s');

$to = new DateTime('2017-08-29 23:59:9');
$to = $to->format('Y-m-d H:i:s');

$orders = Mage::getModel('sales/order')->getCollection()
    ->addAttributeToFilter('created_at', array('from'=>$from, 'to'=>$to))
    ->addAttributeToFilter('status', array('neq' => Mage_Sales_Model_Order::STATE_NEW));
    ->addAttributeToSelect('*');
  • Yur code does exactly the same thing. Still one order is missing for some unknown reason. The only difference is that the missing order was created at 00:14:46 while all the res was created after 06:30:00 ..... why it won't get this one (from 00:14:46)? – Rob D. A. Aug 29 '17 at 14:57
  • Change $from to '2017-08-29 00:00:01' and if it don't work, can you please edit your post with details of the order created at 00:14:46? I'm assuming it has something to do with it. – Stordon Aug 29 '17 at 14:59
  • Ok, good idea,checking :) Nope, same ;( I can't see anything what can cause this issue but to be honest I was testing script on local server where all the orders had the same statuses etc and there was still problem with number of orders, always was -1. – Rob D. A. Aug 29 '17 at 15:02
  • Update created_at from one of today's orders at table sales_flat_order to '2017-08-29 00:13:00' and see if you can see that order with your code – Stordon Aug 29 '17 at 15:13
  • Did you solve it? – Stordon Aug 30 '17 at 12:32
1

Hi make sure pass proper time as well in from and to check below Idea.

$format = 'Y-m-d';
$from   = date($format)." 00:00:00";
$to     = date($format)." 23:59:59";;
  • This is exactly (almost) as I did but this is not an issue. $brom = Mage::getModel('core/date')->date('Y/m/d'); $from = $brom.' 00:00:00'; $now = Mage::getModel('core/date')->date('Y/m/d H:m:i'); Doing exactly what your code does :) – Rob D. A. Aug 29 '17 at 13:55
  • May be order is in "new" state – shyam Aug 29 '17 at 13:59
  • Nope, checked it, tried also select only with state NEW. Nothing! :( I think I know, server time ...... this might be an issue ..... or ..... maybe not ;) – Rob D. A. Aug 29 '17 at 14:03
1

Try this code:

<?php
$from_date  = new DateTime('2017-08-17 00:00:00');
$from_date = $from_date ->format('Y-m-d H:i:s');

$to_date = new DateTime('2017-08-29 23:59:9');
$to_date = $to_date->format('Y-m-d H:i:s');
$orders = Mage::getModel('sales/order')->getCollection()
    ->addAttributeToFilter('created_at', array('from'=>$from_date, 'to'=>$to_date))
    ->addAttributeToFilter('status', array('neq' => Mage_Sales_Model_Order::STATE_COMPLETE));
echo '<pre>'; print_r($orders->getData());
?>
  • Thank you but: first it must be only for one day range from 00:00:00 up tp 23:59:59 andsecondly: the code is exactly the same :) – Rob D. A. Aug 31 '17 at 9:35
  • Seems like it still not working properly if order was created near midnight for some reason, Tonight one of the orders was created at 00:10:13 and script just want see it. – Rob D. A. Sep 1 '17 at 10:26

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.