Magento 1.9 – How to Get Shipment ID in Order Page View.php

ce-1.9.2.3magento-1.9sales-ordershipment

I am using the partial shipment case for multiple shipments and multiple tracking number against one order. For this i have added the new button (Leopard TN) on order view page. Actually when we click on this button its will send the shipment id and order id to the external page by using query string.

I have the order id in the external page by using the below code but i also need to get the shipment id in the next page.

$url = "http://www.exportleftovers.co/leopardmagento/api_call_get.php?order_id={$order->getId()}";
$this->_addButton('get_review_payment_update', array(
    'label'     => Mage::helper('sales')->__('Leopard TN'),
    'onclick' => "window.open('".$url."')"

)); 

Is anyone know how can i get the shipment id and send to the external page?

Best Answer

If you have $order object then you can easily find out shipping id. Here is an example:

if (!$order->canShip()) {
    foreach ($order->getShipmentsCollection() as $shipment) {
        $shipmentId = $shipment->getId();
    }
}

OR

if (!$order->canShip()) {
    $shipment = $order->getShipmentsCollection()->getFirstItem();
    $shipmentId = $shipment->getId();
}

Below Code is working fine:

foreach ($order->getShipmentsCollection() as $shipment) {
    $shipmentId = $shipment->getId();

    $url = "http://www.example.co/filename.php?order_id={$order->getId()}&shipment_id=$shipmentId";

    $this->_addButton('get_review_payment_update', array(
        'label' => Mage::helper('sales')->__('Leopard TN'),
        'onclick' => "window.open('" . $url . "')"

    ));

}

Thanks for the help.