【问题标题】:Prestashop, Generating invoice(pdf) automaticallyPrestashop,自动生成发票(pdf)
【发布时间】:2017-04-13 07:26:27
【问题描述】:

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

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

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

【问题讨论】:

    标签: prestashop prestashop-1.6 invoice


    【解决方案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;,这样它就不是公用文件夹了(你必须创建具有正确权限的文件夹。

    【讨论】:

    • 这就是我所做的。我覆盖 PDF 和 PDFGenerator,我将代码放在页面底部,其中 class 'PDFCore'、'PDFGeneratorCore extends TCPDF' 代码块结束。我创建了具有 chmod 777 -R 权限的目录发票。这是代码路径:$filename = PS_ROOT_DIR.'/invoices/'.$filename;。仍然当我按下查看发票时,我得到一个带有内部服务器错误的白页(正在寻找网络调试)并且没有任何保存
    • 您是否在 overrides/classes/pdf 中使用 php 标签内的上述内容创建了覆盖文件?权限也应该是 775 或 755(从不 777)。之后不要忘记删除(或重命名)文件缓存/class_index.php。您可以检查 error_log 是否有错误。
    • 非常感谢!!!我非常感谢!我现在让它工作了,但还有一件事..我将发票文件夹权限更改为 775,然后我得到错误消息“TCPD 错误:无法创建输出文件:/zzz/zzz/example/invoices/#W003200.pdf”并且 777 一切正常,我想知道为什么会这样?
    • 检查您的 img/p 文件夹的权限。然后使用相同的。并检查文件夹的所有者。如果您使用 root 访问权限创建,您还需要使用 chown 更改为同一所有者(可能是用户、www-data、httpd...)
    • 保存的发票文件名以#like(#W003201.pdf)开头,正常下载没有#,这是为什么呢?我很确定 # 不在 $filename 中
    猜你喜欢
    • 2015-06-04
    • 2017-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    相关资源
    最近更新 更多