Prestashop,自动生成发票(pdf)

Prestashop, Generating invoice(pdf) automatically

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

我也对 google 进行了研究,但这个解决方案不知何故对我不起作用:https://www.prestash...es-in-a-folder/

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

有了这 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;,这样它就不是 public 文件夹(并且您必须创建具有正确权限的文件夹。