Jump to content

Edit History

qu3nd1

qu3nd1

Hi everyone,

I am still looking for the right solution, but while I'm investigating I have to share that @compleus proposal is not the right way to go. First of all, adding a condition "Tools::getValue('printer') == 1" means the pdf file will not be saved when you finally succeed to display the pdf file instead of the blank page with errors inside by clicking on a the link.

Second, even if its not the cause of the issue, you are not required to put an "else" AND a "return" for the normal behavior case. For readability it's best to only use one syntax at a time.
Why removing "else" ? => When you calling the "parent:render()" function with a return, there is no way to access the next "return parent::render($display);" in the same execution cycle.

Additionally, but this is just a personal requirement, I would like the credit notes (oddly named OrderSlip in Prestashop) to also be stored, because like invoices, they are accounting documents that I need to be able to download easily.

So even though the following code doesn't solve the problem of blank PDF while saving it, I show you a more elegant way to write the code:

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

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

qu3nd1

Hi everyone,

I am still looking for the right solution, but while I'm investigating I have to share that @compleus proposal is not the right way to go. First of all, adding a condition "Tools::getValue('printer') == 1" means the pdf file will not be saved when you finally succeed to display the pdf file instead of the blank page with errors inside by clicking on a the link.

Second, even if its not the cause of the issue, you are not required to put an "else" or a "return" for the normal behavior case.
Why removing "else" ? => When you calling the "parent:render()" function, you are calling a function that already performs a "return", so when your conditions allow "parent::render('F');" to be executed, there is no way to access the next "parent::render($display);" in the same execution cycle.
Why removing "return" ? => As I said, when you calling the "parent:render()" function, you are calling a function which already do a "return", you don't have to return an already called return.

Additionally, but this is just a personal requirement, I would like the credit notes (oddly named OrderSlip in Prestashop) to also be stored, because like invoices, they are accounting documents that I need to be able to download easily.

So even though the following code doesn't solve the problem of blank PDF while saving it, I show you a more elegant way to write the code:

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

        parent::render($display);
    }
}
×
×
  • Create New...