magento 2 get order items collection,magento2 get all customers collection,magento 2 get orders by customer id,magento 2 get customer collection,magento 2 get customer collection by id,customer collection in magento 2,magento 2 customer collection filter by attribute,magento2 get order collection by date

recently I want to make a PHP file to get Orders and Customers from a Magento 2 based webshop (like exporting). I have a full code for Magento 1, but for Magento 2 I have searched a lot of things & internet.my client also needed this function for Products but now I have this.That time i was thinking If anybody can provide a full code for Orders and Customers.But after searching a lot i got the solution that can be found below:

get order collection in magento 2 you can use the below code:

 $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
     $orderDatamodel = $objectManager->get('Magento\Sales\Model\Order')->getCollection();
     foreach($orderDatamodel as $orderDatamodel1){
     print_r($orderDatamodel1->getData());

     }

you can get the order items from the order by using

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
     $orderDatamodel = $objectManager->get('Magento\Sales\Model\Order')->getCollection();
     foreach($orderDatamodel as $orderDatamodel1){
     $getid =  $orderDatamodel1->getData("increment_id");
         $orderData = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($getid); 
          $getorderdata = $orderData->getData();
          $orderItems = $orderData->getAllVisibleItems();
          foreach($orderItems as $orderItems){
                    print_r($orderItems->getData());
        }
     }

 

for more information check this http://magentocodes.blogspot.in/2016/10/how-to-get-order-collection-in-magento2.html