vendor/mrpix/shopping-city/src/Services/Navigation.php line 44

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Mrpix\ShoppingCity\Services;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\System\SystemConfig\SystemConfigService;
  7. /**
  8.  * @SuppressWarnings(PHPMD.LongVariable)
  9.  */
  10. class Navigation
  11. {
  12.     protected const CONFIG_CUSTOM_NAV_ACTIVE 'MrpixShoppingCity.config.useCustomNavigation';
  13.     protected const CONFIG_NAV_PROPERTY 'MrpixShoppingCity.config.navigationProperty';
  14.     protected SystemConfigService $configService;
  15.     protected EntityRepositoryInterface $propertyGroupRepository;
  16.     protected PropertyGroupOption $propertyGroupOptionService;
  17.     public function __construct(
  18.         SystemConfigService $configService,
  19.         EntityRepositoryInterface $propertyGroupRepository,
  20.         PropertyGroupOption $propertyGroupOptionService
  21.     ) {
  22.         $this->configService $configService;
  23.         $this->propertyGroupRepository $propertyGroupRepository;
  24.         $this->propertyGroupOptionService $propertyGroupOptionService;
  25.     }
  26.     public function getCustomNavigation(Context $context): array
  27.     {
  28.         $navigationProperty $this->configService->get(self::CONFIG_NAV_PROPERTY);
  29.         if (!$this->configService->get(self::CONFIG_CUSTOM_NAV_ACTIVE) || !$navigationProperty) {
  30.             return [];
  31.         }
  32.         $criteria = new Criteria([$navigationProperty]);
  33.         $criteria->addAssociation('options.sellers');
  34.         $elements $this->propertyGroupRepository->search($criteria$context)->getElements();
  35.         return $this->propertyGroupOptionService->getNonEmptyOptions($elements);
  36.     }
  37. }