0

I am trying to getting order,customer and item details on order success page.

<?php
 $orderid =$block->getOrderId();
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderid);

echo "<pre/>";
print_r($order->getData());
?>

Is anyone have idea how to get using by directly Object Manager?

Please help me.

Thanks

0

This is the proper way to get order details.

protected $order;

public function __construct(
    \Magento\Framework\App\Helper\Context $context,
    \Magento\Sales\Model\Order $order
){
    $this->order = $order;
    parent::__construct($context);
}

public function getOrderDetails($incrementId)
{
    $orderDetail = $this->order->loadByIncrementId($incrementId);
    return $orderDetail;
}

Once you get $orderDetail object properly, then use following code to get Billing, Shipping and Order Item.

<?php $billingAddress = $orderDetail->getBillingAddress()->getData(); ?>
<?php $shippingAddress = $orderDetail->getShippingAddress()->getData(); ?>
<?php $_items = $orderDetail->getAllVisibleItems(); ?>

For Object Manager

<?php 
$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
$orderData = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($block->getOrderId()); 
?>

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.