Magento order invoice pdf in customer account dashboard
Magento order invoice pdf in customer account dashboard

Would you like to fetch magento admin panel feature in front-end.So here is your solution.Now I am going to show you how to fetch Magento order invoice pdf in customer account dashboard.Simply it is a admin panel feature that can only used in sales section of admin panel but here you will getting that feature in front-end.In customer account dashboard instead of view order link you can set view order PDF link which will open invoice pdf of respected order in dashboard of customer account.Generally some clients wants such type of requirement and it is not magento default feature, I am writing this article for giving you one of solution.I have done this solution in my project and I would like to make this solution as public so that other can get benefit on this.Lets come to our topic that how can we implement this.Lets see I am doing one by one.Here I am giving you the full structure of a module because its a simple module.It has taken just two main one is controller and other is config .So lets see what these files contents.

First creating a module you have declare your module in magento. Also I am not giving full details how we can built magento custom module.I am just giving you how simply I have done.
For reference: I have created a new module called JRB_Frontendorderpdf.
As we need a controller for that we have defined the controller rout in our config.xml file , so that we define our custom URL to point out our controller where we can generate PDF. Lets see how I have declare in config.xml file.

Configuration:

Dir: app/code/[CodePool]/[NameSpace]/[ModuleName]/etc/config.xml
e.g: app/code/local/JRB/Frontendorderpdf/etc/config.xml

Now I have declare my controller name as ‘frontendorderpdf’ and I can access my controller function through this name.Here I am just explaing a little bit how controller works in magento.
For example: http://localhost/magento/index.php/frontendorderpdf/pdf/invoicespdf/order_id/2/
This URL can be divided in different part like

  • baseUrl: http://localhost/magento/index.php/

    • it may differ on basis of website URL.you can get by $this->getUrl() or $this->getBaseUrl().
  • frontendName: frontendorderpdf
    • So if we type this name after base URL in browser URL then it we will point to our module controller section .
  • controllerName: pdf
    • controllerName defines which controller class will be called in module.Here we have controllerName called pdf which points to our PdfController class in dir : app/code/local/JRB/Frontendorderpdf/controllers/PdfController.php .Bydefault controllerName can be defined as IndexController.php
  • actionName: invoicespdf
    • actionName defines the function where we implement our logical part.
  • params: order_id/2
    • params are the parameter that used to pass through URL.

So lets see our controller class and action with our custom logic that how we have implements.In same way you can implement your own logic .But here for generating pdf of order invoice ,I have used some logic and model class by using order id.

The Controller:

Dir: app/code/[CodePool]/[NameSpace]/[ModuleName]/controllers/controllerclass
e.g: app/code/local/JRB/Frontendorderpdf/controllers/PdfController.php

Here I have used Mage_Sales_Model_Order_Pdf_Invoice model class by Mage::getModel(‘sales/order_pdf_invoice’) and called the function getPdf() by getPdf($invoices).So my finale code for accessing pdf is : Mage::getModel(‘sales/order_pdf_invoice’)->getPdf($invoices);

Upto to you are able to know how to create pdf with our custom moudle.But our main part is where and how to implement this logic so that we can generate pdf in dashboard of customer account.Lets see where we can set our controller URL to generate PDF.if you will go to dir: app/design/frontend/base/default/template/sales/order then you will be getting two files one is recent.phtml and other is history.phtml.

You can copy those file to your theme directory to override the core file and you can edit without fear. Because you will be safe at the time of up-gradation. Or if you theme has overrided already then edit direct in that folder by taking backup.

history.phtml:

dir: app/design/frontend/base/default/template/sales/order/history.phtml
changed to app/design/frontend/default/default/template/sales/order/history.phtml
or changed to app/design/frontend/themefolder/themefolder/template/sales/order/history.phtml

then go the line number 62(near to) and search for

original:

changed to :

recent.phtml:

dir: app/design/frontend/base/default/template/sales/order/history.phtml
changed to app/design/frontend/default/default/template/sales/order/history.phtml
or changed to app/design/frontend/themefolder/themefolder/template/sales/order/history.phtml

then go the line number 62(near to) and search for

original:

changed to :

Or you can find full module here Order Invoice In Dashboard Frontend.Make sure you have taken backup of your recent.phtml and history.phtml file before installing this into your project.

Hope you have got your solution through the Magento order invoice pdf in customer account dashboard and never forget to share to help others and never hesitate to give comment if you have doubt.

Thanks for visiting.

Magento order invoice pdf in customer account dashboard
The following two tabs change content below.
Jyotiranjan is one of passionate programmer who has been working in magento since 6 years and in the mean time he has developed enormous amount of modules and customisation of sites. He loves to write blogs and travel for long journeying.

Latest posts by Jyotiranjan Biswal (see all)

Tagged on:                                 

5 thoughts on “Magento order invoice pdf in customer account dashboard

  • June 3, 2016 at 12:26 pm
    Permalink

    Hello,
    I just stumbled on your article while looking for a way to get the invoice via url in Magento.
    I followed step by step your tutorial and succeed to get the right link in client dashboard.
    Nonetheless, the link redirected to a 404 page.
    Could you have a clue about the why ?
    Thanks a lot for this article and thanks in advance for any help you could provide.

    Reply
    • June 4, 2016 at 8:30 am
      Permalink

      First of all this tutorial is for the accessing pdf in frontend not backend. So If you are trying to access in backend through custom URL then you need to follow the basis structure of magento backend URL structure I mean all URL needs to be go through magento admin URL else if you are trying to access it through frontend URL then first please check whether your router or controller is pointing or not or you can download full module from this article then check how is works then go for your custom URL.

      Thanks

      Reply
      • June 6, 2016 at 7:05 pm
        Permalink

        I did a clean reinstall of the module from the files you suggest to download, ans everything is working fine.
        Thank you very much !!

        Reply
  • July 24, 2016 at 3:32 pm
    Permalink

    Thanks a lot. It works fine on RWD 1.9.2.4. (mix beetween yours phtml and native rwd).
    I dont know if it is a mistake but the “view order” is not present in modified phtml.

    Reply
    • July 24, 2016 at 5:41 pm
      Permalink

      Actually there is no mistaken been done from your side . You need to just copy my logic to your custom theme, Not whole phtml file . I have explained which line needs t be changed to which one. So again please check the article again and just copy some code which need be but not whole phtml file.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *