custom/plugins/AlbisLease/src/Subscriber/OffcanvasCartPageSubscriber.php line 29

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Albis\AlbisLease\Subscriber;
  3. use Shopware\Core\System\SystemConfig\SystemConfigService;
  4. use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoadedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class OffcanvasCartPageSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @var SystemConfigService
  10.      */
  11.     private $systemConfigService;
  12.     public function __construct(SystemConfigService $systemConfigService)
  13.     {
  14.         $this->systemConfigService $systemConfigService;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             OffcanvasCartPageLoadedEvent::class => 'onOffcanvasCartPageLoaded',
  20.         ];
  21.     }
  22.     public function onOffcanvasCartPageLoaded(OffcanvasCartPageLoadedEvent $event): void
  23.     {
  24.         $salesChannelId $event->getContext()->getSource()->getSalesChannelId();
  25.         $pluginConfig $this->systemConfigService->get('AlbisLease.config'$salesChannelId);
  26.         if(!$pluginConfig['offcanvasCartDisplay']) {
  27.             return;
  28.         }
  29.         
  30.         $page $event->getPage();
  31.         $cart $page->getCart();
  32.         
  33.         $cartAmountGross $cart->getPrice()->getTotalPrice();
  34.         if($cartAmountGross 500) {
  35.             $page->setExtensions([
  36.                 'alibsPaymentAvailable' => true
  37.             ]);
  38.         }
  39.     }
  40. }