local/modules/FairDelivery/Hook/PdfHook.php line 11
<?php
namespace FairDelivery\Hook;
use FairDelivery\FairDelivery;
use FairDelivery\Model\FairDeliveryQuery;
use HookFetes\Model\AgendaFetesQuery;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
class PdfHook extends BaseHook{
public function OnInvoiceDeliveryAddress(HookRenderEvent $event){
$orderId = $event->getArgument('order');
$module = $event->getArgument('module');
$currentFair = FairDeliveryQuery::create()->findOneByOrderId(intval($orderId));
if(!$this->checkModule($module) or is_null($currentFair)){
return;
}
$title = $this->getFairTitleFromFairDelivery($currentFair->getAgendaFetesId());
$html = $this->render('invoiceDelivery.html',['fair_title'=>$title]);
$event->add($html);
}
protected function checkModule($currentModule):bool{
$module_id = FairDelivery::getModuleId();
if (strcmp($currentModule,$module_id)==0){
return true;
}
return false;
}
protected function getFairTitleFromFairDelivery(int $fairId):string{
$selectedFair = AgendaFetesQuery::create()->findOneByFetesId(intval($fairId));
if(is_null($selectedFair)){
return "";
}
return $selectedFair->getTitle();
}
public static function getSubscribedHooks():array
{
return [
"invoice.delivery-address" => [
[
"type" => "pdf",
"method" => "OnInvoiceDeliveryAddress"
]
],
"delivery.delivery-address" => [
[
"type" => "pdf",
"method" => "OnInvoiceDeliveryAddress"
]
]
];
}
}