THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

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

Offline


Bonjour,
Je reviens vers vous avec une nouvelle question !
Voilà mon problème : je veux associer un traitement automatique après la création d’un utilisateur en backOffice. Jusque-là pas de problème.
Maintenant je souhaite que mon traitement automatique me génère un pdf et là c’est le drame !
En fouinant un peu du côté du cœur de thelia, j’ai remarqué une classe PdfEvent, j’ai donc fait un petit bout de code comme ci-dessous, mais mes return ne retourne pas grand-chose.

nb : j'ai utilisé ce même code dans le controller d'un module, cela me génère bien un pdf (aubé oui, mais pdf qd même) .

<?php

namespace Module\Actions;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent;

use Thelia\Core\HttpFoundation\Response;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Event\PdfEvent;

class Customer implements EventSubscriberInterface
{
	public function __construct()
    {
	}
	
    public function updateCustomer(ActionEvent $event)
    {
        
		$html = '
		<page backtop="10mm" backleft="10mm" backright="10mm" backbottom="10mm">
		...
		</page>
		';
		$pdfEvent = new PdfEvent($html);
		
		return Response::create(
            $pdfEvent->getPdf(),
            '200',
            array(
                'Content-type' => "application/pdf",
                'Content-Disposition' => sprintf('Attachment;filename=%s.pdf', 'test.pdf'),
            )
        );
		
    }
	
	public function createCustomer(ActionEvent $event)
    {
		$html = '
		<page backtop="10mm" backleft="10mm" backright="10mm" backbottom="10mm">
		...
		</page>
		';
		$pdfEvent = new PdfEvent($html);
		
		return Response::create(
            $pdfEvent->getPdf(),
            '200',
            array(
                'Content-type' => "application/pdf",
                'Content-Disposition' => sprintf('Attachment;filename=%s.pdf', 'test.pdf'),
            )
        );
    }

    public static function getSubscribedEvents()
    {
        return array(
			"action.updateCustomer" => array("updateCustomer", 100),
			"action.createCustomer" => array("createCustomer", 100)
        );
    }
}

Si vous avez une piste je prend !
Merci !

Offline


Tu as un exemple d'utilisation dans la méthode generateOrderPdf() de la classe BaseController :

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

            $this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent);

            if ($pdfEvent->hasPdf()) {
                return $this->pdfResponse($pdfEvent->getPdf(), $order->getRef());
            }
        } catch (\Exception $e) {
            Tlog::getInstance()->error(
                sprintf(
                    'error during generating invoice pdf for order id : %d with message "%s"',
                    $order_id,
                    $e->getMessage()
                )
            );
        }

OpenStudio Toulouse