I have multiple Order Id in foreach loop, and I want to load or get orders by these order_ids.

I have used this code

if ($requestName == 'sales_order_grid_data_source') {
    if ($result instanceof $this->collection) 
        $select = $this->collection->getSelect();
            foreach($filtered_order_id as $order_id)
                //order id here........... like 6, 7, 8
                //what to do here?? 
                $select->('main_table.entity_id = '.$order_id.'');
        return $this->collection;

Please suggest any solution?

  • Why you do not use Magento collection in order to retrieve orders ? – Franck Garnier Sep 11 '17 at 6:44
  • i already used that – Jay Kapoor Sep 11 '17 at 6:48
  • So you can use the AddFieldToFilter to perform a where IN .... – Franck Garnier Sep 11 '17 at 12:38

I am not able to understand what you are performing but if you need to place where clause in your select query you can perform like this

 $select->where('main_table.entity_id = '.$order_id);

If there are multiple records you and do something like this

$order_id = implode(',', array(1,2,3));
$select->where('main_table.entity_id IN (?)', $order);
| improve this answer | |
  • got this error Notice: Array to string conversion in /var/www/html/magento2/app/code/Learning/HelloPage/Plugin/OrderDataProvider.php on line 113 – Jay Kapoor Sep 11 '17 at 6:01
  • used this one $order_id= array(1,2,3); $select->where('main_table.entity_id IN '.$order_id); – Jay Kapoor Sep 11 '17 at 6:02
  • I have updated my answer when you use "IN" clause you need to pass string not array so You need to convert your array to string. – Priyank Sep 11 '17 at 6:20
  • please keep in touch as im just a beginner in magento..so i will need your help in future – Jay Kapoor Sep 11 '17 at 6:31
  • You can create as many question as you want thats the beauty of this site :) – Priyank Sep 11 '17 at 6:32

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.