Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give the possibility to modify the PDF filename #3208

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Elyos59
Copy link
Contributor

@Elyos59 Elyos59 commented Apr 26, 2024

Add 3 variables in PdfEvent :

* @param string $templateName
* @param string $fileName
* @param string $object

Add default values to this variables in BaseController before dispatch event :

$pdfEvent->setTemplateName($fileName);
$pdfEvent->setFileName($order->getRef());
$pdfEvent->setObject($order);

Now in event listener, we have the possibility to modify Pdf filename.

For example :

TheliaEvents::GENERATE_PDF => ['generatePdf', 256],

public function generatePdf(PdfEvent $event)
{
	$templateName = $event->getTemplateName();
	$object = $event->getObject();
	if(is_a($object,'Thelia\Model\Order')){
		switch($templateName){
			case "invoice":
				$event->setFileName($object->getInvoiceRef());
			break;
			case "delivery":
				$event->setFileName($object->getDeliveryRef());
			break;
		}
	}
}

Add variables
Add set variables to PdfEvent
php-cs-fixer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant