custom/plugins/HuebertAccessoriesDirectly/src/Subscriber/ProductDetailSubscriber.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Huebert\AccessoriesDirectly\Subscriber;
  3. use Shopware\Core\System\SystemConfig\SystemConfigService;
  4. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class ProductDetailSubscriber implements EventSubscriberInterface
  7. {
  8.     protected $systemConfigService;
  9.     public function __construct(
  10.         SystemConfigService $systemConfigService
  11.     )
  12.     {
  13.         $this->systemConfigService $systemConfigService;
  14.     }
  15.     public static function getSubscribedEvents()
  16.     {
  17.         return [
  18.             ProductPageLoadedEvent::class => "onDetailPageLoaded",
  19.         ];
  20.     }
  21.     public function onDetailPageLoaded(ProductPageLoadedEvent $pageLoadedEvent){
  22.         if(array_key_exists('HuebertAccessoriesDirectly'$this->systemConfigService->all($pageLoadedEvent->getSalesChannelContext()->getSalesChannel()->getId()))){
  23.             $config $this->systemConfigService->all($pageLoadedEvent->getSalesChannelContext()->getSalesChannel()->getId())['HuebertAccessoriesDirectly']['config'];
  24.             //legacy code
  25.             $pageLoadedEvent->getPage()->assign(['acessoryOptions' => [
  26.                 'alwaysShow' => !empty($config['alwaysShowAccessories']) ? true false,
  27.                 'accessoryPosition' => $config['accessoryPosition'],
  28.                 'activateVariants' => $config['activateVariants'],
  29.                 'showUnits' => $config['showUnits']
  30.                 ]
  31.             ]);
  32.             //assign HuebertAccessoriesDirectly config
  33.             $pageLoadedEvent->getPage()->assign(['HuebertAccessoriesDirectly' => ['config' => $config]]);
  34.         }
  35.     }
  36. }