Getting Notice Notice: Use of undefined constant sales_flat_order_status_history - assumed 'sales_flat_order_status_history'

514 views Asked by At

I have created below collection query in my custom external magento page--

<?php 

$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set("display_errors", 1);
ini_set('max_execution_time', 3000);
umask(0);
Mage::init('default');
Mage::app();

$start_date='2016-03-01';  
$end_date='2016-04-01';   

$orderCollection=Mage::getModel('sales/order')->getCollection();
try{                    
    $orderCollection->getSelect()->join(array('order_history'=> sales_flat_order_status_history), "main_table.entity_id=order_history.parent_id WHERE (order_history.entity_name = 'invoice' OR order_history.entity_name = 'shipment') AND order_history.status = 'complete' AND order_history.created_at >= '".$start_date."' and order_history.created_at < '".$end_date."' ", array('order_history.parent_id'));
}
catch(Exception $e)
{
        echo $e->getMessage();
}

this query gives me following error--

Notice: Use of undefined constant sales_flat_order_status_history - assumed 'sales_flat_order_status_history'

I don't know, what wrong there ?

1

There are 1 answers

0
shashank On

I don't know, whats the problem was there but I resolved this by converting it into my custom query--

<?php 
$start_date='2016-04-01 00:00:00';  //yyyy-mm-dd  fix
$end_date='2016-05-01 00:00:00';    //yyyy-mm-dd  fix+1


    $query="SELECT `main_table`.* FROM `sales_flat_order` AS `main_table` INNER JOIN `sales_flat_order_status_history` AS `order_history` ON main_table.entity_id=order_history.parent_id WHERE (order_history.entity_name = 'invoice' OR order_history.entity_name = 'shipment') AND order_history.status = 'complete' AND order_history.created_at >= '".$start_date."' and order_history.created_at < '".$end_date."' GROUP BY `main_table`.entity_id";

    $orderCollection=$connectionRead->fetchAll($query);