2

I need to fetch Order details from core table(sale_order_status_history) using order id.

1 Answer 1

2

Using Object Manager Instance

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($IncrementId); //Use increment id here.
$order->getCustomerName(); 

Using Blocks

You need to inject \Magento\Sales\Api\OrderRepositoryInterface class to get order status Add following code in your block

protected $orderRepository;

    public function __construct(
        ...
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        ...
    ) {
        ...
        $this->orderRepository = $orderRepository;
        ...
    }

    public function getOrder($orderId)
    {
        $order = $this->orderRepository->get($orderId);

        return $order;
    }

Call function in your .phtml

$orderId = 1; //Order Id
$order = $block->getOrder($orderId); 
// Check all order data using debug \Zend_Debug::dump($order->debug());
$order->getCustomerName(); 
1
  • @Jayashree is this solution helpful to you ? Commented Nov 30, 2017 at 10:52

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.