custom/plugins/AtlProductConfigurator/src/Subscriber/ProductPageLoadedSubscriber.php line 38

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Atl\ProductConfigurator\Subscriber;
  3. use Atl\ProductConfigurator\Core\Content\ProductConfigurator\ProductConfiguratorEntity;
  4. use Atl\ProductConfigurator\Core\Content\ProductConfigurator\SalesChannel\Price\PriceService;
  5. use Atl\ProductConfigurator\Migration\Migration1628124328ProductExtension;
  6. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ProductPageLoadedSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var PriceService
  12.      */
  13.     private $priceService;
  14.     public function __construct(PriceService $priceService)
  15.     {
  16.         $this->priceService $priceService;
  17.     }
  18.     /**
  19.      * @return string[]
  20.      */
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             ProductPageLoadedEvent::class => 'enrichPrice'
  25.         ];
  26.     }
  27.     /**
  28.      * @param ProductPageLoadedEvent $event
  29.      * @return void
  30.      */
  31.     public function enrichPrice(ProductPageLoadedEvent $event): void
  32.     {
  33.         /** @var ProductConfiguratorEntity $productConfigurator */
  34.         $productConfigurator $event->getPage()->getProduct()->getExtension(Migration1628124328ProductExtension::PRODUCT_EXTENSION);
  35.         if (empty($productConfigurator)) {
  36.             return;
  37.         }
  38.         $this->priceService->calculatePrice($productConfigurator$event->getSalesChannelContext());
  39.     }
  40. }