I am creating shipment programmatically. I want to get shipment id what shipment currently creating. See my code,You can understand my question.

$shipment = $order->prepareShipment($qty);
if ($shipment) {
$shipment->addComment($history_comment, $email && $includeComment);
try {
    $transactionSave = Mage::getModel('core/resource_transaction')
catch (Mage_Core_Exception $e) {
    Mage::getSingleton('adminhtml/session')->addError("Cannot create an empty shipment for ".$order->getIncrementId());

I want to get shipment id of this shipment. Anyone knows how to get..?

1 Answer 1


I did not try but I guess a $shipment->getId() is not working after the $transactionSave->save().

If not, maybe you can use another way to create the shipment: (I found the below code here)

    $itemQty =  $order->getItemsCollection()->count();
    $shipment = Mage::getModel('sales/service_order',$order)->prepareShipment($itemQty);
    $shipment = new Mage_Sales_Model_Order_Shipment_Api();
    $shipmentId = $shipment->create($orderId);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.