0

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 ? Can anybody found out the problem there? thanks in advance.

8
  • Use single or double quotearray('order_history'=> 'sales_flat_order_status_history') in your code.
    – Nits
    Commented Apr 27, 2016 at 12:48
  • Hello Nits, please check my comment for Neklo's Answer. Commented Apr 27, 2016 at 13:05
  • I have checked you script, remove date filter or enter proper date in you collection filter so you will get record.
    – Nits
    Commented Apr 27, 2016 at 13:19
  • @nits, I cant remove date filter its very important, can you tell me what proper date I should entered since Db stores date in same format. And what you have tried? Commented Apr 27, 2016 at 13:21
  • I have checked your script remove date filter in my local setup its working fine, So enter proper date (which contain data from your order) in you collection filter, you will get record.
    – Nits
    Commented Apr 27, 2016 at 13:27

1 Answer 1

0

Try to change sales_flat_order_status_history to 'sales_flat_order_status_history' and you will get

SELECT main_table.*, order_history.parent_id 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 >= '2016-03-01' and order_history.created_at < '2016-04-01'

2
  • Hello Neklo, if I do like you suggested, and then I try this echo count($orderCollection) it prints nothing. and If I wanna iterate this collection using foreach(), it also does not work. Commented Apr 27, 2016 at 12:52
  • try add echo $orderCollection->getSelect(); after join in try catch and you will see query then try exequte it in mysql
    – Neklo.com
    Commented Apr 27, 2016 at 20:29

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.