Jump to content

How to save pdf invoices manually and automatically?


Somepub
 Share

Recommended Posts

I have solution for saving invoices to my server

 

I override the pdf files

Here is my code:

 

PDF.PHP

<?php

class PDF extends PDFCore
{
    public function render($display = true)
    {
        if($this->template == PDF::TEMPLATE_INVOICE)
            parent::render('F', true); //This renders to automatic save

        return parent::render($display);
    }
}

?>

PDFGenerator.PHP

<?php

 class PDFGenerator extends PDFGeneratorCore
{
    public function render($filename, $display = true)
    {
        if (empty($filename)) {
            throw new PrestaShopException('Missing filename.');
        }

        $this->lastPage();

        if ($display === true) {
            $output = 'D';
        } elseif ($display === false) {
            $output = 'S';
        } elseif ($display == 'D') {
            $output = 'D';
        } elseif ($display == 'S') {
            $output = 'S';
        } elseif ($display == 'F') {
            $output = 'F';
            $filename = '/place/folder/invoices/print_it/'.str_replace("#", "", $filename); //file name starts with #, replacing for printing
        } else {
            $output = 'I';
        }

        return $this->output($filename, $output);
    }
}

?>

All is working fine with my automatic invoice save, but when I'm downloading invoice manually(clicking view invoice in adminpanel), I'm getting an error or just a blank pdf file. So I can understand that this problem occurs with PDF.PHP file..

 

I tried to render both, but that dident help:

 

PDF.PHP

<?php

class PDF extends PDFCore
{
    public function render($display = true)
    {
        if($this->template == PDF::TEMPLATE_INVOICE)
            parent::render('F', true);
            parent::render('I', true);

        return parent::render($display);
    }
}

?>

It only renders the first of the parent::render, if  parent::render('I', true) was first, I could download invoices manually, but automatic invoice save would be blank

 

Soo.. is there any solution to this?

Share this post


Link to post
Share on other sites

  • 5 months later...

Hello @compleus,

I did found a solution for this!
 

class PDF extends PDFCore
{
    public function render($display = true)
    {
        if($this->template == PDF::TEMPLATE_INVOICE && Tools::getValue('printer') == 1) {
			// Output PDF to local file
            parent::render('F');
            //echo "<script>window.close();</script>"; // added javascript for automatic closure after link print clicked
        }
        else {
            return parent::render($display); // Saving manually
        }
    }
}

The link for downloading pdf:

http://www.example.com/admin/index.php?controller=AdminPdf&submitAction=generateInvoicePDF&id_order=3230&print=1

Share this post


Link to post
Share on other sites

  • 4 years later...

Hi @Somepub, I'd like to integrate this aswel on my PS installation. 

I can't seem to find the pdf.php file. Where do I find these files and where do I override them? 

Thanks!

Lucas

Share this post


Link to post
Share on other sites

1 minute ago, LucasV said:

Hi @Somepub, I'd like to integrate this aswel on my PS installation. 

I can't seem to find the pdf.php file. Where do I find these files and where do I override them? 

Thanks!

Lucas

Just found the files in classes/pdf/  Now I'm still lokkig for the correct way to override. 

Share this post


Link to post
Share on other sites

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More