custom/plugins/MojeBambinoExtensions/src/Subscriber/CategoryPageSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. namespace MojeBambino\Extensions\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Doctrine\DBAL\Connection;
  5. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
  6. use MojeBambino\Extensions\Struct\Kafelki;
  7. class CategoryPageSubscriber implements EventSubscriberInterface {
  8.     
  9.     private Connection $connection;
  10.     
  11.     public function __construct(Connection $connection){
  12.         $this->connection $connection;
  13.     }
  14.     
  15.     public static function getSubscribedEvents(): array{
  16.         return [NavigationPageLoadedEvent::class => 'onCategoryPageLoaded'];
  17.     }
  18.     
  19.     public function onCategoryPageLoaded(NavigationPageLoadedEvent $event): void{
  20.         $category $event->getPage()->getCmsPage();
  21.         $IdKat "";
  22.         
  23.         $sections $category->getSections();
  24.         $i 1;
  25.         foreach($sections->getElements() as $elem){
  26.             foreach($elem->getBlocks()->getElements() as $elem1){
  27.                 if($elem1->getType()=="product-listing"){
  28.                     foreach($elem1->getSlots() as $slot){
  29.                         $ost $slot->getData()->getListing()->getCurrentFilters();
  30.                         $IdKat $ost['navigationId'];
  31.                     } 
  32.                 }
  33.             }
  34.             $i++;
  35.         }
  36.         
  37.         $kafelki = new Kafelki();
  38.         
  39.         if($IdKat && $IdKat!=""){
  40.             $query $this->connection->createQueryBuilder();
  41.             $query->select(['k.*'])->from('kafelki_kategorie''kk');
  42.             $query->join('kk''kafelki''k''kk.Id=k.Id');
  43.             $query->join('kk''category''c''kk.IdKat=c.auto_increment');
  44.             $query->where('hex(c.id)= :IdKat')->andWhere("k.active=1");
  45.             $query->setParameter('IdKat'$IdKat);
  46.             $statement $query->execute();
  47.             $kaf $statement->fetchAll(\PDO::FETCH_ASSOC);
  48.             $kafelki->setKafle($kaf);
  49.         }
  50.         
  51.         $category->addExtension('kafelki'$kafelki);
  52.     }
  53. }