I have the following custom model:
class CompanyName_Orders_Model_FetchOrderInfo extends Mage_Core_Model_Abstract {
private function createDate($lookBeforeDateInDays = null){
if(($lookBeforeDateInDays===null) || (!is_int($lookBeforeDateInDays))){
// 'No date or invalid date supplied.
return $lookBeforeDateInDays=date(now());
}else{
$varToTime = strtotime("-".$lookBeforeDateInDays." day");
return $lookBeforeDateInDays=date("Y-m-d 00:00:00",$varToTime);
}
}
public function unpaid($lookBackInDays = null) {
echo $lookBeforeDateInDays=$this->createDate($lookBackInDays);
echo '<br>';
/*
* Get Orders where not cancelled or complete and have not captured any funds.
*/
$missingOrders = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', array('nin' => array('canceled','complete')))
->addAttributeToFilter('base_total_paid', array('null'=>true))
->addAttributeToFilter('created_at',array('to'=>$lookBeforeDateInDays));
echo $missingOrders->count().'<br>';
echo $missingOrders->getSelect();
return true;
}
}
Please excuse the bonus "echo's" in the model - they're for debugging.
I am attempting to replicated the same results as you'd see in Sales > Orders when Filter = Processing and Purchased On (To) = [date]. The createDate function take a numerical input, converts X days ago using strtotime or sets the date to now if no input is provided.
My Problem
The date is outputting correctly, but where $missingOrders->count() should be, lets say, 53 - it may be 35.
I've verified that it isn't because of the "status" filter so that leads me to believe that my server time differs from Magento's time. How can I sync the two so that the results line up? And, since this is in a model, shouldn't the timezone match up anyway?