Jump to content

Save invoice PDF in specific folder when order is complete


renaud2263
 Share

Recommended Posts

Hi,

As the title of the topic, I would like to save the PDF invoices automatically when order is complete.

I overrided the 2 PDF classes :

<?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);
    }
}

?>

and PDFGenerator

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 = _PS_ROOT_DIR_.'/Compta/tva-new/invoices/'.$filename;
        } else {
            $output = 'I';
			
        }

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

Then : the files are saved in the folder, but if a customer (or from admin) wants to download his invoice, the file is blank. 

So how it's possible to have both : invoices downloadable from admin or frontend AND automatically saved in the folder.

Many thanks in advance.

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