Get Order Information From Order ID using Repository
<?php
Class Techsolutionblog {
protected
$orderRepository
;
public
function
__construct(
\Magento\Sales\Api\OrderRepositoryInterface
$orderRepository
){
$this
->orderRepository =
$orderRepository
;
}
public
function
MyFunction()
{
$orderId
= 2;
$order
=
$this
->orderRepository->get(
$orderId
);
echo
$order
->getIncrementId();
echo
$order
->getGrandTotal();
echo
$order
->getSubtotal();
//fetch payment information
print_r(
$order
->getPayment()->getData());
//fetch customer information
echo
$order
->getCustomerId();
echo
$order
->getCustomerEmail();
echo
$order
->getCustomerFirstname();
echo
$order
->getCustomerLastname();
//fetch whole billing information
print_r(
$order
->getBillingAddress()->getData());
echo
$order
->getBillingAddress()->getCity();
echo
$order
->getBillingAddress()->getRegionId();
echo
$order
->getBillingAddress()->getCountryId();
//fetch whole shipping information
print_r(
$order
->getShippingAddress()->getData());
echo
$order
->getShippingAddress()->getCity();
echo
$order
->getShippingAddress()->getRegionId();
echo
$order
->getShippingAddress()->getCountryId();
}
}
Get Order Information From Order ID
<?php
$orderId
=102;
$objectManager
= \Magento\Framework\App\ObjectManager::getInstance();
$order
=
$objectManager
->create(
'Magento\Sales\Api\Data\OrderInterface'
)->load(
$orderId
);
print_r(
$order
->getData());
echo
$order
->getIncrementId();
echo
$order
->getGrandTotal();
echo
$order
->getSubtotal();
?>
Get Order Items Information
<?php
$orderId
= 102;
$objectManager
= \Magento\Framework\App\ObjectManager::getInstance();
$order
=
$objectManager
->create(
'Magento\Sales\Api\Data\OrderInterface'
)->load(
$orderId
);
//Loop through each item and fetch data
foreach
(
$order
->getAllItems()
as
$item
)
{
print_r(
$item
->getData());
echo
$item
->getId();
echo
$item
->getProductType();
echo
$item
->getQtyOrdered();
echo
$item
->getPrice();
}
?>
Get Order Payment Information
<?php
$orderId
= 102;
$objectManager
= \Magento\Framework\App\ObjectManager::getInstance();
$order
=
$objectManager
->create(
'Magento\Sales\Api\Data\OrderInterface'
)->load(
$orderId
);
print_r(
$order
->getPayment()->getData());
echo
$order
->getPayment()->getAmountPaid();
echo
$order
->getPayment()->getMethod();
echo
$order
->getPayment()->getAdditionalInformation(
'method_title'
);
?>
Get Order Customer Information
<?php
$orderId
= 201;
$objectManager
= \Magento\Framework\App\ObjectManager::getInstance();
$order
=
$objectManager
->create(
'Magento\Sales\Api\Data\OrderInterface'
)->load(
$orderId
);
echo
$order
->getCustomerId();
echo
$order
->getCustomerEmail();
echo
$order
->getCustomerFirstname();
echo
$order
->getCustomerLastname();
?>
Get Order Shipping And Billing Information
<?php
$orderId
= 201;
$objectManager
= \Magento\Framework\App\ObjectManager::getInstance();
$order
=
$objectManager
->create(
'Magento\Sales\Api\Data\OrderInterface'
)->load(
$orderId
);
print_r(
$order
->getBillingAddress()->getData());
echo
$order
->getBillingAddress()->getCity();
echo
$order
->getBillingAddress()->getRegionId();
echo
$order
->getBillingAddress()->getCountryId();
print_r(
$order
->getShippingAddress()->getData());
echo
$order
->getShippingAddress()->getCity();
echo
$order
->getShippingAddress()->getRegionId();
echo
$order
->getShippingAddress()->getCountryId();
?>