custom/static-plugins/GlobusSW6/src/Subscriber/BadgesPrioritySubscriber.php line 33

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace GlobusSW6\Subscriber;
  3. use GlobusSW6\Service\BadgesPriorityService;
  4. use GlobusSW6\Service\IaneoBusinessExtension;
  5. use Shopware\Core\Content\Product\ProductCollection;
  6. use Shopware\Core\Framework\Api\Context\AdminApiSource;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntitySearchResultLoadedEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class BadgesPrioritySubscriber implements EventSubscriberInterface
  10. {
  11.     /** @var BadgesPriorityService */
  12.     private $badgesPriorityService;
  13.     /** @var IaneoBusinessExtension */
  14.     private $ianeoBusinessExtensionService;
  15.     public function __construct(BadgesPriorityService $badgesPriorityServiceIaneoBusinessExtension $ianeoBusinessExtensionService)
  16.     {
  17.         $this->badgesPriorityService $badgesPriorityService;
  18.         $this->ianeoBusinessExtensionService $ianeoBusinessExtensionService;
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             'product.search.result.loaded' => ['onProductLoaded'100]
  24.         ];
  25.     }
  26.     public function onProductLoaded(EntitySearchResultLoadedEvent $event)
  27.     {
  28.         // do not fire event in backend context
  29.         if ($event->getContext()->getSource() instanceof AdminApiSource) {
  30.             if ($event->getContext()->getSource()->isAdmin()) {
  31.                 return;
  32.             }
  33.         }
  34.         /** @var ProductCollection $products */
  35.         $products $event->getResult()->getEntities();
  36.         if ($products === null) {
  37.             return;
  38.         }
  39.         if ($event->getName() !== 'product.search.result.loaded') {
  40.             return;
  41.         }
  42.         $badgeContent $this->badgesPriorityService->checkBadgeContent($products);
  43.         $this->ianeoBusinessExtensionService->addAttributes($products$badgeContent'disturber');
  44.     }
  45. }