Jump to content

Generating invoice(pdf) automatically


Recommended Posts

So I'm looking for a solution to save invoice automatically into my server folder, when I press view invoice as the generated URL occurs (http://domainurl/index.php?controller=AdminPdf&token=token&submitAction=generateInvoicePDF&id_order=id).
I also did research on google, but this solution, somehow didnt work for me: https://www.prestashop.com/forums/topic/465729-automatically-generate-invoices-in-a-folder/

Do you want to bulk generate them for all your orders or setup an automatic job for the next ones?
To make it automatic to save all your orders' pdfs, you need to edit root/tools/tcpdf/tcpdf.php:

protected function sendOutputData($data, $length) {
        // the content length may vary if the server is using compression
        header('Content-Length: '.$length);
    //save to disk if it is a PDF about an order  
    $id_order = Tools::getValue('id_order');
    if ($id_order)
        file_put_contents(_PS_ROOT_DIR_."your/path/to/pdfs/order-{$id_order}.pdf", $data);

    echo $data;

I'm using prestashop 1.6.1, when I tried this code, it dident save anything to  savedir and I got an internal server error when I opened the generated URL

Link to comment
Share on other sites


Storing the invoice by using tools/tcpdf/tcpdf.php would even work better if you could add the invoice date to the invoice name.

I didn't manage it yet in this place. Do you have any idea to solve this problem?

And btw the standard invoice file name does not contain the id_order, but the invoice number!

Link to comment
Share on other sites



Well... I tried using wget but still stuck, because the downloaded pdf rejects. The error:"Removing www.example.ee/admin111/index.php?controller=AdminPdf, since it should be rejected".


Terminal: PS in other lang

example@server64:~$ wget -e robots=off -A pdf -r -l1 http://www.example.ee/admin1111/index.php?controller=AdminPdf'>http://www.example.ee/admin1111/index.php?controller=AdminPdf&token=37b476c0666f5eb588837a8f7774eb66&submitAction=generateInvoicePDF&id_order=3188'>http://www.example.ee/admin1111/index.php?controller=AdminPdf'>http://www.example.ee/admin1111/index.php?controller=AdminPdf&token=37b476c0666f5eb588837a8f7774eb66&submitAction=generateInvoicePDF&id_order=3188
[1] 14337
[2] 14338
[3] 14339
example@server64:~$ --2017-04-17 14:52:13--  http://www.example.ee/admin1111/index.php?controller=AdminPdf'>http://www.example.ee/admin1111/index.php?controller=AdminPdf
Lahendan http://www.example.ee (www.example.ee)...
Loon ühendust serveriga www.example.ee (www.example.ee)||:80... ühendus loodud.
HTTP päring saadetud, ootan vastust... 302 Found
Asukoht: index.php?controller=AdminLogin&token=37b476c0666f5eb588837a8f7774eb66&redirect=AdminPdf [järgnev]
--2017-04-17 14:52:13--  http://www.example.ee/admin1111/index.php?controller=AdminPdf'>http://www.example.ee/admin1111/index.php?controller=AdminPdf&token=37b476c0666f5eb588837a8f7774eb66&redirect=AdminPdf
Kasutan ühendust serveriga www.example.ee:80.
HTTP päring saadetud, ootan vastust... 200 OK
Pikkus: 6283 (6,1K) [text/html]
Salvestan: `http://www.example.ee/admin1111/index.php?controller=AdminPdf'>http://www.example.ee/admin1111/index.php?controller=AdminPdf'

100%[======================================>] 6 283       --.-K/s   aeg 0s     

2017-04-17 14:52:13 (12,6 MB/s) - `http://www.example.ee/admin1111/index.php?controller=AdminPdf'>http://www.example.ee/admin1111/index.php?controller=AdminPdf' salvestatud [6283/6283]

Kustutan http://www.example.ee/admin1111/index.php?controller=AdminPdf'>http://www.example.ee/admin1111/index.php?controller=AdminPdf, kuna see peaks olema tagasi lükatud.

LÕPETATUD --2017-04-17 14:52:13--
Täielik aeg: 0,3s
Alla laetud: 1 faili, 6,1K aeg 0s (12,6 MB/s)

Edited by Somepub (see edit history)
Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...