I have created a custom module for order tracking.
Now when the order is completed the shipment id is generated.
So, How to get the shipment id?
I have my block like this :
<?php
/**
* Copyright © 2016 Codazon. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Codazon\AjaxCartPro\Block;
class Trackorder extends \Magento\Framework\View\Element\Template
{
protected $orderRepository;
protected $_coreRegistry;
public function __construct(
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\View\Element\Template\Context $context,
array $data = []
)
{
$this->_coreRegistry = $coreRegistry;
$this->orderRepository = $orderRepository;
parent::__construct($context, $data);
}
public function getOrderStatus()
{
$orderId = $this->_coreRegistry->registry('order_id');
$order = $this->orderRepository->get($orderId);
$state = $order->getState(); // Print Order State(Complete, Processing, ....)
return $state;
}
public function getShipmentID()
{
$orderId = $this->_coreRegistry->registry('order_id');
$order = $this->orderRepository->get($orderId);
$shipment = $order->getShipmentsCollection();
return $shipment;
}
}
But getShipmentID()
this function does not work for me.
How to resolve this problem?
How to get shipment id If order is completed.