local/modules/FairDelivery/Hook/PdfHook.php line 11

  1. <?php
  2. namespace FairDelivery\Hook;
  3. use FairDelivery\FairDelivery;
  4. use FairDelivery\Model\FairDeliveryQuery;
  5. use HookFetes\Model\AgendaFetesQuery;
  6. use Thelia\Core\Event\Hook\HookRenderEvent;
  7. use Thelia\Core\Hook\BaseHook;
  8. class PdfHook extends BaseHook{
  9.     public function OnInvoiceDeliveryAddress(HookRenderEvent $event){
  10.         $orderId $event->getArgument('order');
  11.         $module $event->getArgument('module');
  12.         $currentFair FairDeliveryQuery::create()->findOneByOrderId(intval($orderId));
  13.         if(!$this->checkModule($module) or is_null($currentFair)){
  14.             return;
  15.         }
  16.         $title $this->getFairTitleFromFairDelivery($currentFair->getAgendaFetesId());
  17.         $html $this->render('invoiceDelivery.html',['fair_title'=>$title]);
  18.         $event->add($html);
  19.     }
  20.     protected function checkModule($currentModule):bool{
  21.         $module_id FairDelivery::getModuleId();
  22.         if (strcmp($currentModule,$module_id)==0){
  23.             return true;
  24.         }
  25.         return false;
  26.     }
  27.     protected function getFairTitleFromFairDelivery(int $fairId):string{
  28.         $selectedFair AgendaFetesQuery::create()->findOneByFetesId(intval($fairId));
  29.         if(is_null($selectedFair)){
  30.             return "";
  31.         }
  32.         return $selectedFair->getTitle();
  33.     }
  34.     public static function getSubscribedHooks():array
  35.     {
  36.         return [
  37.             "invoice.delivery-address" => [
  38.                 [
  39.                     "type" => "pdf",
  40.                     "method" => "OnInvoiceDeliveryAddress"
  41.                 ]               
  42.                 ],
  43.                 "delivery.delivery-address" => [
  44.                     [
  45.                         "type" => "pdf",
  46.                         "method" => "OnInvoiceDeliveryAddress"
  47.                     ]               
  48.                     ]
  49.         ];
  50.     }
  51.  
  52. }