Somepub Posted April 12, 2017 Share Posted April 12, 2017 Hello, 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) { if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) { // 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 More sharing options...
tuk66 Posted April 12, 2017 Share Posted April 12, 2017 You can see the URL in the BackOffice. What about to load the PDFs using wget, shell script and probably cron? Link to comment Share on other sites More sharing options...
Somepub Posted April 13, 2017 Author Share Posted April 13, 2017 How can I do that? I tried wget the URL and I got only html page not generated pdf Link to comment Share on other sites More sharing options...
tuk66 Posted April 13, 2017 Share Posted April 13, 2017 Can help http://stackoverflow.com/questions/6416880/wget-problem-downloading-pdfs-from-website http://unix.stackexchange.com/questions/331751/download-pdf-files-using-wget Link to comment Share on other sites More sharing options...
eleazar Posted April 13, 2017 Share Posted April 13, 2017 @tuk66 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 More sharing options...
Somepub Posted April 17, 2017 Author Share Posted April 17, 2017 (edited) @tuk66 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)... 111.11.111.111 Loon ühendust serveriga www.example.ee (www.example.ee)|111.11.111.111|: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 April 17, 2017 by Somepub (see edit history) Link to comment Share on other sites More sharing options...
tuk66 Posted April 17, 2017 Share Posted April 17, 2017 Yes, you need to be logged in. http://stackoverflow.com/questions/1324421/how-to-get-past-the-login-page-with-wget https://askubuntu.com/questions/161778/how-do-i-use-wget-curl-to-download-from-a-site-i-am-logged-into Link to comment Share on other sites More sharing options...
Somepub Posted April 18, 2017 Author Share Posted April 18, 2017 @tuk66 Hmm.. yeah I forgot to login, but still no success, maybe I'm writing the code wrong: wget -x --load-cookies cookies.txt -e robots=off -A pdf -r -l1 http://www.example.ee/admin1111/index.php?controller=AdminPdf&token=44q236505aa6f5eb516737a8d534eb66&submitAction=generateInvoicePDF&id_order=3194 Link to comment Share on other sites More sharing options...
stweet Posted November 30, 2017 Share Posted November 30, 2017 up Link to comment Share on other sites More sharing options...
Somepub Posted November 30, 2017 Author Share Posted November 30, 2017 @stweet Hello, Please look at this post: link Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now