How to get Order Details programmatically in magento2
Hello magento friends in this post i'm shere with you to How to get Order Details programmatically in magento2
➤ In this program we are used to get order details progrmetically using - Magento\Sales\Api\Data\OrderInterface - class in our custom block Wheelbuilderjson file
getParam() : is used for get url Parameter
like our url is : www.magento.com/user/details/index/order_id/2020
how to get order_id in our file :
here solution to get order_id -
$this->getRequest()->getParam("order_id") - these f
$orderId = $this->getRequest()->getParam("order_id");
$orderId is 2020
<?php
namespace Dww\Quote\Block\Adminhtml;
use Magento\Sales\Model\Order;
use Magento\Sales\Api\Data\OrderInterface;
class Wheelbuilderjson extends \Magento\Backend\Block\Template
{
protected $order;
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
OrderInterface $orderInterface,
\Magento\Framework\Serialize\Serializer\Json $json,
\Magento\Sales\Model\Order $order,
array $data = []
) {
$this->orderInterface = $orderInterface;
$this->order = $order;
$this->json = $json;
parent::__construct($context, $data);
}
public function getOrderDeatils()
{
$orderId = $this->getRequest()->getParam("order_id");
$order = $this->order->load((int)$orderId);
foreach ($order->getItems() as $item) {
$part = $item["customized_parts"];
if(!empty($part)){
$jsonDecode = $this->json->unserialize($part);
return $jsonDecode;
}
}
return $part= "";
}
}
Tags:
magento2