custom/plugins/BjerregaardTheme/src/Subscriber/CheckoutConfirmPageSubscriber.php line 26

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace BjerregaardTheme\Subscriber;
  3. use DateTime;
  4. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Throwable;
  7. class CheckoutConfirmPageSubscriber implements EventSubscriberInterface
  8. {
  9.     private string $publicDir;
  10.     public function __construct(string $publicDir)
  11.     {
  12.         $this->publicDir $publicDir;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmPageSubscriber',
  18.         ];
  19.     }
  20.     public function onCheckoutConfirmPageSubscriber(CheckoutConfirmPageLoadedEvent $event): void
  21.     {
  22.         $dates = [];
  23.         $file $this->publicDir "/shipping.json";
  24.         if (!file_exists($file)) {
  25.             return;
  26.         }
  27.         try {
  28.             $dates json_decode(file_get_contents($file));
  29.             $dates array_filter($dates, fn($date) => isset($date->Calendar) && $date->Calendar === 'DANMARK');
  30.             array_walk($dates, fn(&$date) => $date = (new DateTime($date->Date))->format('Y-n-j'));
  31.         } catch (Throwable) {
  32.         }
  33.         $event->getPage()->addArrayExtension('bjerregaard', [
  34.             'disabledDates' => array_unique($dates),
  35.         ]);
  36.     }
  37. }