0

I found how to create an invoice programmatically but nothing about to create a shipment pdf.
So far I can create the shipment for items but I have no clue how create the pdf.

1

If you have already shipment of order then you can create shipment pdf. using sale pdf shipment model ,pdf has been created.

code:

if ($shipment = Mage::getModel('sales/order_shipment')->load($shipmentId)) {
$pdf = Mage::getModel('sales/order_pdf_shipment')->getPdf(array($shipment));
    }

Create Shipment first:

You need to create ship first without shipment create pdf is not created.

Try below

$order=Mage::getModel('sales/order')->load($orderId);

$qty=array();
foreach($order->getAllItems() as $eachOrderItem){

    $Itemqty=0;
     $Itemqty = $eachOrderItem->getQtyOrdered()
            - $eachOrderItem->getQtyShipped()
            - $eachOrderItem->getQtyRefunded()
            - $eachOrderItem->getQtyCanceled();
    $qty[$eachOrderItem->getId()]=$Itemqty;

}


$email=true;
$includeComment=true;
$comment="test Shipment";

if ($order->canShip()) {
         /* @var $shipment Mage_Sales_Model_Order_Shipment */
        /* prepare to create shipment */
     $shipment = $order->prepareShipment($qty);
      if ($shipment) {
          $shipment->register();
          $shipment->addComment($comment, $email && $includeComment);
          $shipment->getOrder()->setIsInProcess(true);
            try {
                $transactionSave = Mage::getModel('core/resource_transaction')
                    ->addObject($shipment)
                    ->addObject($shipment->getOrder())
                    ->save();
                $shipment->sendEmail($email, ($includeComment ? $comment : ''));
            } catch (Mage_Core_Exception $e) {
                var_dump($e);
            }

      }

}

See more about:Programmatically create Shipment of a new order in magento

  • Ok, I will try it. And this is also possible with shipment_items? I mean single items from the table "sales_flat_shipment_item" although there are related items which has the same parent_id. – Timo.Klement Apr 1 '15 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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