0

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->register();
$shipment->addComment($history_comment, $email && $includeComment);
$shipment->getOrder()->setIsInProcess(true);
try {
    $transactionSave = Mage::getModel('core/resource_transaction')
            ->addObject($shipment)
            ->addObject($shipment->getOrder())
            ->save();
            }
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

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)

if($order->canShip()){
    $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);
}
0

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.