custom/plugins/MadYoutubeVideoOptions/src/Subscriber/ProductSubscriber.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace MadYoutubeVideoOptions\Subscriber;
  4. use MadYoutubeVideoOptions\MadYoutubeVideoOptions;
  5. use MadYoutubeVideoOptions\Service\MadCustomFieldService;
  6. use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity;
  7. use Shopware\Storefront\Page\Product\ProductPageCriteriaEvent;
  8. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class ProductSubscriber  implements EventSubscriberInterface
  11. {
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             ProductPageLoadedEvent::class => 'onProductPageLoaded',
  16.         ];
  17.     }
  18.     public function onProductPageLoaded(ProductPageLoadedEvent $event): void
  19.     {
  20.         $product $event->getPage()->getProduct();
  21.         $customFields $product->getCustomFields();
  22.         if (isset($customFields['mad_product_youtube_options'])){
  23.             $youtube_options str_replace(array("{""}",'"'),"",$customFields['mad_product_youtube_options']);
  24.             $youtube_options explode(","$youtube_options);
  25.             $customFields['mad_product_youtube_options'] = array();
  26.             foreach($youtube_options as &$option){
  27.                 $option str_replace(array(" "),"",$option);
  28.                 $option explode(":"$option);
  29.                 if($option[0]){
  30.                     $customFields['mad_product_youtube_options'][$option[0]] =  $option[1];
  31.                 }
  32.             }
  33.         }
  34.         $product->setCustomFields($customFields);
  35.     }
  36. }