custom/plugins/ImnxxCrmBlackoutScenario/src/Subscriber/CrmBlackoutScenarioSubscriber.php line 34

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace ImnxxCrmBlackoutScenario\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  5. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  6. use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
  7. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  8. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
  9. use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent;
  10. use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoadedEvent;
  11. use Shopware\Storefront\Page\Address\Listing\AddressListingPageLoadedEvent;
  12. use Shopware\Storefront\Page\Address\Detail\AddressDetailPageLoadedEvent;
  13. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  14. use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
  15. use Shopware\Core\Checkout\Cart\Event\LineItemAddedEvent;
  16. use Shopware\Storefront\Page\Search\SearchPageLoadedEvent;
  17. use Symfony\Component\HttpFoundation\Session\Session;
  18. class CrmBlackoutScenarioSubscriber implements EventSubscriberInterface {
  19.     public static function getSubscribedEvents(): array {
  20.         return [
  21.             GenericPageLoadedEvent::class => 'onPageLoaded',
  22.         ];
  23.     }
  24.     public function onPageLoaded(GenericPageLoadedEvent $event) {
  25.         if (isset($_SESSION['crm_online'])) {
  26.             if ($_SESSION['crm_online'] === false || $_SESSION['crm_online'] === null) {
  27.                 $crm_online_status['crm_online'] = false;
  28.                 $event->getPage()->assign($crm_online_status);
  29.             }
  30.             $event->getPage()->assign(['crm_online' => $_SESSION['crm_online']]);
  31.         } else {
  32.             $event->getPage()->assign(['crm_online' => true]);
  33.         }
  34.     }
  35. }