Prestashop,自动生成发票(pdf)

时间:2017-04-13 07:26:28

标签: prestashop prestashop-1.6 invoice

所以我正在寻找一种解决方案,将发票自动保存到我的服务器文件夹中,当我按生成的URL时查看发票(http://www.example.com/admin11111/index.php?controller=AdminPdf&token=“令牌”& submitAction = generateInvoicePDF& id_order =“id” )。

我也在google做过研究,但是这个解决方案在某种程度上对我不起作用:https://www.prestash...es-in-a-folder/

来自Prestashop论坛我得到了一些建议,我应该使用shell脚本,但使用像wget或其他的shell下载只能得到我的html文件,因为当我在Prestashop后台下载发票时...需要一些时间来生成和下载保存稍后会出现。

1 个答案:

答案 0 :(得分:1)

有了这2个覆盖,你就可以做到这一点。

覆盖PDF.php:

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

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

覆盖PDFGenerator.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 = _PS_ROOT_DIR_.'/'.$filename;
        } else {
            $output = 'I';
        }

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

请记住选择_PS_ROOT_DIR_以外的其他文件夹。这只是为了测试。请尝试$filename = _PS_ROOT_DIR_.'/../invoices/'.$filename;,因此它不是公用文件夹(您必须使用正确的权限创建文件夹。

相关问题