protected $_searchCriteriaBuilder;
protected $_shipmentRepositoryInterface;
protected $_logger;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Sales\Api\ShipmentRepositoryInterface $shipmentRepositoryInterface,
\Psr\Log\LoggerInterface $logger,
array $data = []
) {
$this->_searchCriteriaBuilder = $searchCriteriaBuilder;
$this->_shipmentRepositoryInterface = $shipmentRepositoryInterface;
$this->_logger = $logger;
parent::__construct($context, $data);
}
public function getShipmentDetails($orderId)
{
$shipmentData = array();
if($orderId > 0) {
$searchCriteria = $this->_searchCriteriaBuilder->addFilter('order_id', $orderId)->create();
try {
$shipments = $this->_shipmentRepositoryInterface->getList($searchCriteria);
$shipmentData = $shipments->getItems();
} catch (Exception $exception) {
$this->_logger->critical($exception->getMessage());
$shipmentData = null;
}
}
return $shipmentData;
}
Recent Comments