custom/static-plugins/GlobusSW6/src/Subscriber/ShippingTimesSubscriber.php line 39

Open in your IDE?
  1. <?php
  2. namespace GlobusSW6\Subscriber;
  3. use GlobusSW6\Service\IaneoBusinessExtension;
  4. use GlobusSW6\Service\ShippingTimeService;
  5. use Shopware\Core\Content\Product\ProductCollection;
  6. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntitySearchResultLoadedEvent;
  9. class ShippingTimesSubscriber implements EventSubscriberInterface
  10. {
  11.     /** @var ShippingTimeService */
  12.     private $shippingTimeService;
  13.     /** @var IaneoBusinessExtension */
  14.     private $ianeoBusinessExtensionService;
  15.     /**
  16.      * ShippingTimesDetailPage constructor.
  17.      * @param ShippingTimeService $shippingTimeService
  18.      * @param IaneoBusinessExtension $ianeoBusinessExtensionService
  19.      */
  20.     public function __construct(ShippingTimeService $shippingTimeServiceIaneoBusinessExtension $ianeoBusinessExtensionService)
  21.     {
  22.         $this->shippingTimeService $shippingTimeService;
  23.         $this->ianeoBusinessExtensionService $ianeoBusinessExtensionService;
  24.     }
  25.     public static function getSubscribedEvents()
  26.     {
  27.         return [
  28.             'product.search.result.loaded' => 'onProductLoaded'
  29.         ];
  30.     }
  31.     public function onProductLoaded(EntitySearchResultLoadedEvent $event){
  32.         /** @var ProductCollection $products */
  33.         $products $event->getResult()->getEntities();
  34.         if($products === null){
  35.             return;
  36.         }
  37.         if($event->getName() !== 'product.search.result.loaded'){
  38.             return;
  39.         }
  40.         // collect shipping times for each product
  41.         $shippingTimes $this->shippingTimeService->checkShippingTime($products);
  42.         // add shipping time flags to product extension
  43.         $this->ianeoBusinessExtensionService->addAttributes($products$shippingTimes'shippingTimes');
  44.     }
  45. }