<?php declare(strict_types=1);
namespace Mrpix\ShoppingCity\Services;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SystemConfig\SystemConfigService;
/**
* @SuppressWarnings(PHPMD.LongVariable)
*/
class Navigation
{
protected const CONFIG_CUSTOM_NAV_ACTIVE = 'MrpixShoppingCity.config.useCustomNavigation';
protected const CONFIG_NAV_PROPERTY = 'MrpixShoppingCity.config.navigationProperty';
protected SystemConfigService $configService;
protected EntityRepositoryInterface $propertyGroupRepository;
protected PropertyGroupOption $propertyGroupOptionService;
public function __construct(
SystemConfigService $configService,
EntityRepositoryInterface $propertyGroupRepository,
PropertyGroupOption $propertyGroupOptionService
) {
$this->configService = $configService;
$this->propertyGroupRepository = $propertyGroupRepository;
$this->propertyGroupOptionService = $propertyGroupOptionService;
}
public function getCustomNavigation(Context $context): array
{
$navigationProperty = $this->configService->get(self::CONFIG_NAV_PROPERTY);
if (!$this->configService->get(self::CONFIG_CUSTOM_NAV_ACTIVE) || !$navigationProperty) {
return [];
}
$criteria = new Criteria([$navigationProperty]);
$criteria->addAssociation('options.sellers');
$elements = $this->propertyGroupRepository->search($criteria, $context)->getElements();
return $this->propertyGroupOptionService->getNonEmptyOptions($elements);
}
}