custom/static-plugins/LDSCustom/src/Subscriber/Product.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace LDSCustom\Subscriber;
  4. use LDSCustom\Service\VariantPrices;
  5. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class Product implements EventSubscriberInterface
  8. {
  9.     private $service;
  10.     public function __construct(VariantPrices $service)
  11.     {
  12.         $this->service $service;
  13.     }
  14.     /**
  15.      * @return array
  16.      */
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             ProductPageLoadedEvent::class => 'onProductPageLoaded',
  21.         ];
  22.     }
  23.     public function onProductPageLoaded(ProductPageLoadedEvent $event): void
  24.     {
  25.         $configuratorSettings $event->getPage()->getConfiguratorSettings();
  26.         $product $event->getPage()->getProduct();
  27.         if (=== $configuratorSettings->count()) {
  28.             return;
  29.         }
  30.         $options $this->service->getVariantPrices(
  31.             $product,
  32.             $configuratorSettings->getElements(),
  33.             $event->getSalesChannelContext()
  34.         );
  35.         if ([] === $options) {
  36.             return;
  37.         }
  38.         $event->getPage()->assign(['ldsVariantPricesOptions' => $options['available'],]);
  39.     }
  40. }