I'm use following code to catch order information in this Observer : "sales_order_save_after"
public function execute(\Magento\Framework\Event\Observer $observer){
$orderData = $observer->getEvent()->getOrder()->getData();
$orderId = $orderData['increment_id'];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
$orderItems = $order->getItems();
foreach ($orderItems as $item) {
error_log(print_r($item->getData(), true));
}
}
When I place order as guest customer it logs information of all items, But when I Login as a customer and placing order it doesn't log anything because "items" Array is empty.
How can I get item information from order of customer that is logged-in?