THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline

#1 Pdfgenerator 2.5

(13-01-2023 17:38:47)


Avec ce module,
quand j'essaie d'appeler une url,
je recois template file cannot be found

Le fichier .html est au bon endroit dans le template avec les bon droits.


J'ai modifié le controlleur comme suit :

<?php
/*************************************************************************************/
/*      Copyright (c) Franck Allimant, CQFDev                                        */
/*      email : thelia@cqfdev.fr                                                     */
/*      web : http://www.cqfdev.fr                                                   */
/*                                                                                   */
/*      For the full copyright and license information, please view the LICENSE      */
/*      file that was distributed with this source code.                             */
/*************************************************************************************/

/**
 * Created by Franck Allimant, CQFDev <franck@cqfdev.fr>
 * Date: 24/01/2019 19:38
 */

namespace PdfGenerator\Controller;

use PdfGenerator\PdfGenerator;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\PdfEvent;
use Thelia\Core\Event\TheliaEvents;
/*2.5*/
use Thelia\Core\Template\TemplateHelperInterface;
use Thelia\Exception\TheliaProcessException;
use Thelia\Log\Tlog;

class GeneratorController extends BaseFrontController
{
    public function downloadPdf($template, $outputFileName)
    {
        return $this->renderPdfTemplate($template, $outputFileName, false);
    }

    public function viewPdf($template, $outputFileName)
    {
        return $this->renderPdfTemplate($template, $outputFileName, true);
    }

    /**
     * @param $templateName
     * @param $outputFileName
     * @param $browser
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function renderPdfTemplate($templateName, $outputFileName, $browser, $templateHelper = null)
    {
        $html = $this->renderRaw(
            $templateName,
            [],
            /*2.5*/
           $this->getTemplateHelper()->getActiveFrontTemplate()
        );

        try {
            $pdfEvent = new PdfEvent($html);

            /*modifié pour 2.5*/
            $this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent);

            if ($pdfEvent->hasPdf()) {
                return $this->pdfResponse($pdfEvent->getPdf(), $outputFileName, 200, $browser);
            }
        } catch (\Exception $e) {
            Tlog::getInstance()->error(
                sprintf(
                    'error during generating PDF document %s.html with message "%s"',
                    $templateName,
                    $e->getMessage()
                )
            );
        }

        throw new TheliaProcessException(
            $this->getTranslator()->trans(
                "We're sorry, this PDF document %name is not available at the moment.",
                [ '%name' => $outputFileName],
                PdfGenerator::DOMAIN_NAME
            )
        );
    }
}