PrestaShop libraries replacement

﹥>﹥吖頭↗ 提交于 2019-12-13 10:19:54

问题


I use PrestaShop 1.6.1.4 and I want to change the library tcpdf with dompdf.

I use this form for creating invoices.

What are the best practices for a library exchange?


回答1:


I created inside override the tools folder and I put us dompdf-master found here https://github.com/dompdf/dompdf.

Instead inside override/classes/pdf i copied PDFGenerator.php, there is in classes/pdf.

In PDFGenerator.php add:

require_once('/../override/tools/dompdf-master/dompdf/Dompdf.php');
require_once('/../override/tools/dompdf-master/autoload.inc.php');
include('/../override/tools/dompdf-master/dompdf/dompdf_config.inc.php');
use Dompdf\Dompdf;
use Dompdf\Options;

The class becomes:

class PDFGenerator extends DOMPDF

Eliminates the render() function and replace it with:

public function render($filename, $display = true)
{
    if (empty($filename)) {
        throw new PrestaShopException('Missing filename.');
    }

    $html = $this->header.$this->content.$this->footer;
    //die($html);    

    $options = new Options();
    $options->set('A4','potrait');
    $options->set('enable_css_float',true);
    $options->set('isHtml5ParserEnabled', true);

    $dompdf = new DOMPDF($options);
    $dompdf->load_html($html);

    $dompdf->render();

    $dompdf->stream($filename);
}

Then i deleted cache/class_index.php



来源:https://stackoverflow.com/questions/38498044/prestashop-libraries-replacement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!