1

I displayed button Download [ last column in below image ] in Sales Order grid page for each order. Once i click on button, I want to generate pdf with information of "Customer address" of that order.

enter image description here

I checked Firegento & comwrap , but both will generate only invoice, shipping, credit memos only.

app/code/community/Raveinfosys/Deleteorder/Block/Adminhtml/Sales/Order/Render - Delete.php

class Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_Render_Delete extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        $getData = $row->getData();     
        $orderID = $getData['entity_id'];      
        $link = '<a href="'.$download.'">Download</a>;';
        return $link;
    }
}

Please guide me on this....

1
+200

Try this:

a. app/code/community/Raveinfosys/Deleteorder/Block/Adminhtml/Sales/Order/Render - Delete.php

class Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_Render_Delete extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        $getData = $row->getData();     
        $orderId = $getData['entity_id'];      
        $link = '<a href="'.$this->getPdfGenerateUrl($orderId).'">Download</a>;';
        return $link;
    }


    public function getPdfGenerateUrl($orderId)
    {
        return Mage::helper("adminhtml")->getUrl('*/raveinfosys/generatePdf', array('order_id' => $orderId));
    }

}

b. Now create a file called RaveinfosysController.php: app/code/community/Raveinfosys/Deleteorder/controllers/Adminhtml/RaveinfosysController.php with this content:

<?php
class Raveinfosys_Deleteorder_Adminhtml_RaveinfosysController extends Mage_Adminhtml_Controller_Action
{

    public function generatePdfAction()
    {
        $orderId = $this->getRequest()->getParam('order_id');
        $order = Mage::getModel('sales/order')->load($orderId);
        $billingAddress = $order->getBillingAddress();

        $pdf = new Zend_Pdf();
        $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
        $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
        $page->setFont($font, 12);
        $width = $page->getWidth();
        $i=0;

        $page->drawText('Order Id# '.$order->getIncrementId(), 20, $page->getHeight()-20);
        $page->drawText("TO", 20, $page->getHeight()-40);
        $page->drawText($billingAddress->getStreet(). " ". $billingAddress->getRegion(), 20, $page->getHeight()-60);
        $page->drawText($billingAddress->getCountry(), 20, $page->getHeight()-80);
        $page->drawText($billingAddress->getRegionCode(), 20, $page->getHeight()-100);

        $pdf->pages[] = $page;
        //$pdf->render();

        $this->_prepareDownloadResponse('info'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
                '.pdf', $pdf->render(), 'application/pdf');

        //$this->_redirectReferer();
    }

}

This should work.

  • thanks, i got : Fatal error: Call to a member function getFormated() on a non-object in = > $page->drawText($billingAddress->getFormated(), 20, $page->getHeight()-40); – Baby in Magento Nov 27 '17 at 5:50
  • That means your $order is not an object. Check if order_id is correct in your url (in grid). It should be raveinfosys/generatePdf/order_id/NUMBER – Adarsh Khatri Nov 27 '17 at 6:02
  • onclick download button, I got this result in url : sitename.com/index.php/admin/raveinfosys/generatePdf/key/6e70b958e72adcd9b69368ec317afd69/ – Baby in Magento Nov 27 '17 at 6:06
  • once i hide that line : $page->drawText($billingAddress->getFormated(), 20, $page->getHeight()-40); & when i click on download button , then it downloaded pdf with content as 'Order Id#` – Baby in Magento Nov 27 '17 at 6:45
  • 1
    Thanks a trillion for your help, it's really great that you helped in night also...... – Baby in Magento Nov 27 '17 at 13:17

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.