1

I want to add opportunity to print pdf invoices from shipping grid. I take print action from order controller

 public function pdfinvoicesAction(){
$shipmentIds = $this->getRequest()->getPost('shipment_ids');
$flag = false;
if (!empty($shipmentIds)) {
    foreach ($shipmentIds as $shipmentId) {
        $invoices = Mage::getResourceModel('sales/order_invoice_collection')
            ->setOrderFilter($shipmentId)
            ->load();
        if ($invoices->getSize() > 0) {
            $flag = true;
            if (!isset($pdf)){
                $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
            } else {
                $pages = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
                $pdf->pages = array_merge ($pdf->pages, $pages->pages);
            }
        }
    }
    if ($flag) {
        return $this->_prepareDownloadResponse(
            'invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').'.pdf', $pdf->render(),
            'application/pdf'
        );
    } else {
        $this->_getSession()->addError($this->__('There are no printable documents related to selected shipments.'));
        $this->_redirect('*/*/');
    }
}
$this->_redirect('*/*/');

}

But it print invoices which hasn't belongs to the shipments selected. Can anybody help with this?

  • You need to add a massAction if you're going to print selected invoices. – seanbreeden Jan 25 '15 at 2:56
  • Hi, yes I have massAction $this->getMassactionBlock()->addItem('pdfinvoices_order', array( 'label'=> Mage::helper('sales')->__('PDFа'), 'url' => $this->getUrl('*/sales_shipment/pdfinvoices'), )); – Vertius Jan 25 '15 at 9:56

Your Answer

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

Browse other questions tagged or ask your own question.